I have a simple Java Maven program that I created in Intellij. It has Two classes Main and Read. I was able to build a jar and run it. However if I zip the source code into a folder , would I be able to compile it using command line? Something like javac ? How should I do this? Shall I run commands in Java folder in the project? Many thanks.
-
If you use Maven there is no reason to compile your program with javac. Maven does exactly that, and more.vanje– vanje2019-04-03 10:14:23 +00:00Commented Apr 3, 2019 at 10:14
Add a comment
|
1 Answer
As far as the Java class loader is concerned, a .jar or .zip file is the same as a directory containing the the files, and .jar and .zip files are generally used to distribute compiled Java packages. Here you can read more about it.
For compiling the zip file: use the -classpath option to javac and java. We could, for example:
javac -classpath .:/users/johnr/java:/opt/jdk1.1.6/lib/classes.zip Hello.java
3 Comments
user4046073
Thanks. To clarify this a bit more, this command is how to run Hello.jave after all the code has been zipped to classes.zip? I'm not sure if there are two classes, how to compile them all with javac?
Pooya Panahandeh
to run the java file inside the folder you can write:
javac *.java by adding this command to the beginning you can compile multiple file. easy way is writing file name like: javac -classpath .:/users/johnr/java:/opt/jdk1.1.6/lib/classes.zip Hello.java GoodBye.javaPooya Panahandeh
Also check this link, here you can find more explanation about running multiple file.