Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do Eclipse's "export jar" from the command line

In my workflow for creating a jar to distribute my code, I currently:

  1. right-click on my project in Eclipse
  2. select "Export"
  3. select "JAR file"
  4. uncheck the top-level files like .classpath, .project
  5. check only "export generated class files"
  6. click "finish"

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?

like image 272
lacker Avatar asked Jan 12 '12 00:01

lacker


1 Answers

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

like image 196
hopia Avatar answered Oct 14 '22 14:10

hopia