docker run -it --rm -v $PWD:/app/ maven:3-jdk-8 su -c"cd /app && mvn archetype:generate -DgroupId=info.hamdifourati.helloworld -DartifactId=hello-world -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false"
docker run -it --rm -v $PWD/hello-world:/app/ maven:3-jdk-8 su -c "cd /app && mvn package"
The second argument is used to specify the Main class to run
docker run -it --rm -v $PWD/hello-world:/app/ maven:3-jdk-8 su -c "cd /app && java -cp target/*.jar info.hamdifourati.helloworld.App"
You can specify the Main class by editing the
pom.xml
file. Add inside the<project>
tag
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.example.grpc.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
And then run
docker run -it --rm -v $PWD/hello-world:/app/ maven:3-jdk-8 su -c "cd /app && java -jar target/*.jar"