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.
Asked
Active
Viewed 595 times
0

user4046073
- 821
- 4
- 18
- 39
-
If you use Maven there is no reason to compile your program with javac. Maven does exactly that, and more. – vanje Apr 03 '19 at 10:14
1 Answers
2
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

Pooya Panahandeh
- 578
- 7
- 21
-
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? – user4046073 Apr 03 '19 at 07:51
-
1to 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.java` – Pooya Panahandeh Apr 03 '19 at 08:11
-
1Also check this [link](https://stackoverflow.com/questions/4800781/how-to-compile-multiple-java-source-files-in-command-line), here you can find more explanation about running multiple file. – Pooya Panahandeh Apr 03 '19 at 08:14