I've a Java project in IntelliJ which builds and executes successfully. Now I would like to package the code (i.e. package it so it can be executed in a linux environment).
The directory structure is:
../parser/src/com/test1/java
bash-4.2$ ls -R
external Jparser Main.java
./external:
java-json.jar
./Jparser:
JsonParser.class JsonParser.java
So far I've executed javac -cp ../external/java-json.jar Parser.java
What is the next step? Is it class path of Parser.java to main?
Edit: I'm specifically interested to learn how to to the above in command line for better understanding of Java. I love gradle, maven, IDEs, but they all have sorts of black box magic which is often convenient but leaves the beginner user thinking they know Java builds....
It is not clear whether Jparser
is a package inside your main module, or it is a sub-module directory.
javac -cp ../external/java-json.jar Main.java Jparser/JsonParser.java
jar cvf my.jar Main.class JsonParser
javac -cp ../external/java-json.jar *.java
jar cvf my.jar *.class
Then to run it: java -cp my.jar:../external/java-json.jar Main
A better approach to organize the build would be to use Maven https://maven.apache.org/ or Ant http://ant.apache.org/
IDEA can generate Ant builds using Build->Generate Ant Build
.