How to create a Dockerfile with Maven on a Windows box and then sent to a remote Linux server for building an image and then ran?

I have a Java project building with Maven. I want to dynamically create a Dockerfile when it builds. My end goal is to create an executable Jar and Dockerfile, send them both to a server where the Dockerfile is used to build the image that will execute the Jar and then run the container. This will be used mostly in a build/test process so I don’t want to commit any code or publish my Jar to an Artifactory of sort before each test. I feel that the 4 separate authentications to the server is very inefficient. I’ve tried to find a Maven plugin that can do all of this but without any luck. Is there a plugin that that can do all of this for me or just a better way than what i’m currently doing? Thanks in advance. I will mark answers as helpful if so and will mark the correct answer as such. Thanks in advance! Below is my current progress with the Maven plugin work.

<!--This plugin will Transfer the executable JAR and Dockerfile file to a remote server, build an image and run it -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <!-- Create a Docerfile --> 
                            <echo file="${project.build.directory}/Dockerfile.txt" 
                                  message="FROM java:8${line.separator}" 
                                  append="true"/>
                            <echo file="${project.build.directory}/Dockerfile.txt"
                                  message="ADD ${pi.deployDirectory}/${project.build.finalName}-jar-with-dependencies.jar ${pi.deployDirectory}/demo/${project.build.finalName}-jar-with-dependencies.jar${line.separator}"
                                  append="true"/>
                            <echo file="${project.build.directory}/Dockerfile.txt" 
                                  message="CMD [&quot;java&quot;,&quot;-jar&quot;,&quot;${pi.deployDirectory}/demo/${project.build.finalName}-jar-with-dependencies.jar&quot;]"
                                  append="true"/>

                            <!-- ensure the target directory exists on the Server -->
                            <sshexec host="${server.host}" port="${server.port}" username="${server.user}" password="${server.password}" 
                                     trust="true" failonerror="false" verbose="true" 
                                     command="mkdir --parents ${server.deployDirectory}"/>

                            <!-- copy the JAR file to the Server -->
                            <scp
                                file="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar"
                                todir="${server.user}:${server.password}@${server.host}:${server.deployDirectory}"
                                port="${server.port}" trust="true" verbose="true" failonerror="true">
                            </scp> 

                            <!-- copy the Dockerfile file to the Server -->
                            <scp
                                file="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar"
                                todir="${server.user}:${server.password}@${server.host}:${server.deployDirectory}"
                                port="${server.port}" trust="true" verbose="true" failonerror="true">
                            </scp> 

                            <!-- TODO: Add section that will on the remote server build a container using the new Dockerfile and then run that container -->

                            <!-- run the JAR file on the Server no in container-->
                            <sshexec host="${server.host}" port="${server.port}" username="${server.user}"
                                     password="${server.password}" trust="true" failonerror="false"
                                     verbose="true" 
                                     command="java -jar ${server.deployDirectory}/${project.build.finalName}-jar-with-dependencies.jar"/>
                        </tasks>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-jsch</artifactId>
                    <version>1.9.6</version>
                </dependency>
            </dependencies>
        </plugin>

  • Unable to use userns remap in Docker
  • Building meta-virtualization layer in yocto
  • Docker - increase size of the /dev/shm
  • How to build a Docker container with a running MySQL?
  • docker-compose error when I run bundle
  • at command inside docker container
  • How can I access the Kubernetes service through ClusterIP
  • docker + django : loop + break using forms
  • Dotnet Core publish to IIS from Mac
  • docker-compose error what is this?
  • Docker 1.12 Port Fowarding Services Across Nodes
  • Wordpress: already installed error when applying new DB
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.