How to do Eclipse's “export jar” from the comm

2019-02-12 11:35发布

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?

1条回答
该账号已被封号
2楼-- · 2019-02-12 12:33

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

查看更多
登录 后发表回答