0

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.

1
  • If you use Maven there is no reason to compile your program with javac. Maven does exactly that, and more. Commented Apr 3, 2019 at 10:14

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

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?
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.java
Also check this link, here you can find more explanation about running multiple file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.