I have some Java code on my machine that I run from the command line. I want to create a runnable .jar file from this code so that I can distribute my application more easily.
The code is in four folders, called fol_a, fol_b, fol_c, and fol_d. Each of these contains a /bin subfolder, containing the .class files, and two of them (fol_a and fol_b) also contain a /lib folder, containing some .jar files that the code needs.
fol_d contains the class to run, Demo, which is in a package called machineLearning. The full path to the class is
fol_d/bin/machineLearning/Demo
I currently run the code from the command line as follows:
$ cd fol_d/bin
$ java -cp ".:../../fol_a/bin:../../fol_a/lib/*:../../fol_b/bin:../../fol_b/lib/*:../../fol_c/bin" machineLearning.Demo <param_1> <param_2> ... <param_5>
where <param_1> to <param_5> are the arguments given to the Main method in Demo.
What I want is to create one single .jar file that contains all the code that is necessary to execute Demo successfully, i.e., the code in fol_a through fol_d. I then want to be able to run this .jar file from the command line, giving it the arguments that go to the Main method in Demo. Something like this:
$ java -jar MyApplication.jar <param_1> ... <param_5>
Is this possible? How would I do this? I've been trying to find an answer online, but the amount of information confuses me.
UPDATE
Right! So it seems that all I needed to do was this:
- copy the contents of the
bindirectories to a new dirmyapp - make a manifest.txt file that specifies the main class to run, as well as the classpath
- jar
myapp:$ jar cmf manifest.txt myapp.jar -C myapp/ . - execute the jar:
$ java -jar myapp.jar <arg_1> <arg_2> ... <arg_n>