使用 ANT 和 Eclipse 自动创建 JAR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11422600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:32:03  来源:igfitidea点击:

Create automatically JAR with ANT and Eclipse

javaeclipseantjar

提问by user1516059

I want to make the file build automatically using Eclipse. I need this file creates the JAR of the application. And if it were possible, I would like to insert the command to pass some test of JUnit. How can I do all of this automatically?

我想使用 Eclipse 自动构建文件。我需要这个文件来创建应用程序的 JAR。如果可能的话,我想插入命令以通过一些 JUnit 测试。我怎样才能自动完成所有这些?

回答by dash1e

Generally to create jar files in Eclipse I do this things:

通常要在 Eclipse 中创建 jar 文件,我会这样做:

  1. create an ant file with the necessary code to create the jar file I need
  2. configure the ant file to be processed when something change in my project files: and to do this I open the project properties, I choose Builders, "New..."and I add a Ant builderthat use my ant file
  1. 使用必要的代码创建一个 ant 文件来创建我需要的 jar 文件
  2. 配置要在我的项目文件中发生变化时处理的 ant 文件:为此,我打开项目属性,选择Builders“新建...”,然后添加一个使用我的 ant 文件的Ant 构建器

In the ant files I put for example something similar:

在 ant 文件中,我放了一些类似的东西:

<project name="My Project" default="createjar">    
  <property name="projectHome" location="." />
  <target name="createjar">
    <jar destfile="${projectHome}/file.jar" basedir="${projectHome}/bin" />
  </target>    
</project>

You can add other instructions to the ant file and process whatever you need after the jar creation. But my suggestion is to not launch JUnit test on very file change, can be very ugly.

您可以在 ant 文件中添加其他指令,并在创建 jar 后处理您需要的任何内容。但我的建议是不要在非常文件更改时启动 JUnit 测试,这可能非常难看。