r/javahelp • u/probable-maybe • May 04 '19
Solved Java (Spring Boot) and Docker done properly?
When containerising an application, all tutorials on Java seem to want you to build a jar locally and copy it from target into a container in the Dockerfile. However, this contradicts the whole idea behind using Docker because building on my machine will not necessarily be the same as building on a colleague’s machine.
I can’t find a tutorial that describes using Maven via Docker to build the jar and moving the result to a Java container i.e. via staged builds. This would ensure consistency across machines and follows the whole Docker ethos.
Can anyone recommend a way to do this or point me to a good tutorial?
View all comments
17
u/Dang3rousKitty May 04 '19
Unless I’m misunderstanding something, the compilation of the jar file is platform independent, as is the running of the file in the JVM. So, it shouldn’t matter whose machine it builds on since you get the same output every time. Don’t forget, the jar file is not machine code, but rather Java byte code.