如何从命令行中执行Eclipse的“导出jar”

时间:2021-05-18 23:13:25

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

在我创建一个jar来分发我的代码的工作流程中,我目前:

  1. right-click on my project in Eclipse
  2. 在Eclipse中右键单击我的项目。
  3. select "Export"
  4. 选择“导出”
  5. select "JAR file"
  6. 选择“JAR文件”
  7. uncheck the top-level files like .classpath, .project
  8. 取消检查*文件,如.classpath、.project
  9. check only "export generated class files"
  10. 只检查“导出生成的类文件”
  11. click "finish"
  12. 单击“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?

这确保了.class文件是最新的,并创建了jar。我希望从命令行来做同样的事情,但是创建jar文件的大多数文档似乎只是对已经存在的文件进行了破坏,而没有创建.class文件的阶段。如何从命令行执行此操作?

1 个解决方案

#1


4  

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文件,可以使用“jar”实用程序。jar文件基本上是一个存档文件(实际上,您可以使用任何zip工具来提取jar内容)。要创建一个jar文件,您需要指定“c”选项和您编译并希望包含的所有.class文件。jar命令行模仿tar命令。例如,要添加根文件夹为com的类文件,输入:

  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.

然而,构建jar文件的更简单的方法是使用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

从ant网站查看本教程,它给出了一个典型的ant构建文件示例:http://ant.apache.org/manual/tutorial/helloworldwithant.html

#1


4  

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文件,可以使用“jar”实用程序。jar文件基本上是一个存档文件(实际上,您可以使用任何zip工具来提取jar内容)。要创建一个jar文件,您需要指定“c”选项和您编译并希望包含的所有.class文件。jar命令行模仿tar命令。例如,要添加根文件夹为com的类文件,输入:

  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.

然而,构建jar文件的更简单的方法是使用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

从ant网站查看本教程,它给出了一个典型的ant构建文件示例:http://ant.apache.org/manual/tutorial/helloworldwithant.html