I have a secure remote system that does not have an internet connection and I want to run a maven project on it. Is it possible for me to build the project on my local machine and then copy the compiled files to the remote machine to run there?
Asked
Active
Viewed 25 times
0
-
Of course. That's how you run Java files on machines you can't build or don't want to build on. But you'll need ask the dependencies, which will determine what your final artifact consists of. – Dave Newton Jun 12 '18 at 22:22
-
@DaveNewton After building my maven project, can't I run a specific java file that has a main method using javac command in the command line? – user2470087 Jun 13 '18 at 21:58
-
Of course you can (not with javac of course). You still need all your dependencies on the classpath, which means if a jar, a fat jar or manifest. – Dave Newton Jun 13 '18 at 22:31
-
@DaveNewton How can I add the dependencies on the classpath? I found that after building the maven project I can use the command "java -cp . myPackage.classname" inside the target/classes folder to run the java class but I still haven't figured out how to add dependencies like log4j to this. – user2470087 Jun 14 '18 at 00:41
-
You build a jar with all the dependencies in it. – Dave Newton Jun 14 '18 at 01:07
-
@DaveNewton Can you elaborate on the last point a bit, please. I'm sorry I am a bit new to this. – user2470087 Jun 14 '18 at 18:25
-
If your program has no external dependencies (e.g., code you didn't write, like Maven dependencies, jars, etc.) then it's not relevant. If it does, either the jar artifact you distribute needs to include all those dependencies in it ("fat jar") or it needs to include a manifest file with those dependencies listed and those dependencies must be present on the connection-less machine. A fat jar is easier. See for example https://stackoverflow.com/a/16222965/438992. – Dave Newton Jun 14 '18 at 18:40
-
Thanks. I got the project working on the remote machine. Initially, for the classpath, I was specifying only the folder in which the jars were present but when I specified the individual jar paths it worked. – user2470087 Jun 14 '18 at 21:22
-
:thumbs-up: Cool. Yeah, Java's classpath options are a bit sparse. – Dave Newton Jun 14 '18 at 21:33