In my workflow for creating a jar to distribute my code, I currently:
This ensures the .class files are up-to-date and creates the jar. I would like to do this same thing from the command line, but most documentation for creating jars seems to be just jarring up files that already exist, without the phase of creating the .class files. How can I do this from the command line?
To manually create a jar file, you can use the "jar" utility. A jar file is basically an archive file (in fact, you can use any zip tool to extract the jar contents). To create a jar file, you specify the "c" option and all the .class files that you compiled and that you want included. The jar command-line mimics the tar command. So, for example, to add your class files whose root folder is com, you type:
jar cf test.jar com
Optionally, you can add manifest data in the form of a manifest file to specify a default executable and other information.
However, a simpler way to build a jar file is to just use ant.
Checkout this tutorial from the ant website, which gives an example of a typical ant build file: http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With