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>

  • Is it possible to add multiple source files in dokker.json?
  • Unable to do port forwarding: socat not found. Kubernetes on Docker
  • Failed to execute git command in Docker container using fig/crane
  • What does the command gcloud docker -a do?
  • Can't start mongo with docker command, but can with /bin/bash inside container (with data volume)
  • How to expose a service running inside a docker container, bound to localhost
  • Node.js web application not running properly in Docker stack
  • Possible to write a text file (or some other file) in a docker container but access it when container has stopped?
  • Dockerfile with entrypoint for executing bash script
  • Install redmine plug-in using docker container
  • Unable to run an Android application in a Docker container with Gitlab-CI
  • Running 'docker-compose up' raises “No module named fnctl” error on Windows
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.