如何在Eclipse Java项目中自动生成.jar文件 [英] How Do I Automatically Generate A .jar File In An Eclipse Java Project

查看:186
本文介绍了如何在Eclipse Java项目中自动生成.jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Eclipse Java项目。它包含一个名为dist的文件夹。在该文件夹中是.jar文件。



如何在此项目中设置东西,以确保此.jar文件在任何时候更新项目中的.java文件已被重新编译?



谢谢。

解决方案

创建一个Ant文件,告诉Eclipse来构建它。只有两个步骤,每个都是简单的,分步说明如下。






步骤1
创建一个build.xml文件并添加到程序包资源管理器中:

 <?xml version = 1.0?> 
<! - 用于生成Jar文件的Ant构建系统的配置 - >
< project name =TestMaindefault =CreateJar>
< target name =CreateJardescription =创建Jar文件>
< jar jarfile =Test.jarbasedir =。 includes =*。class/>
< / target>
< / project>

Eclipse应该看起来像下面的截图。注意build.xml上的Ant图标。



步骤2
右键单击项目中的根节点。
- 选择属性
- 选择Builders
- 选择新建
- 选择Ant Build
- 在主选项卡中,完成build.xml文件的路径 bin 文件夹。






检查输出



Eclipse输出窗口(名为Console)应在构建后显示以下内容:

  Buildfile:/home/<user>/src/Test/build.xml 

CreateJar:
[jar]构建jar:/home/<user>/src/Test/Test.jar
BUILD SUCCESSFUL
总时间:152毫秒


I have an Eclipse Java project. It contains a folder named "dist". In that folder is a .jar file.

How can I set things up in this project to make sure this .jar file is updated any time one of the .java files in the project has been re-compiled?

Thanks.

解决方案

Create an Ant file and tell Eclipse to build it. There are only two steps and each is easy with the step-by-step instructions below.


Step 1 Create a build.xml file and add to package explorer:

<?xml version="1.0" ?>
<!-- Configuration of the Ant build system to generate a Jar file --> 
<project name="TestMain" default="CreateJar">
  <target name="CreateJar" description="Create Jar file">
        <jar jarfile="Test.jar" basedir="." includes="*.class" />
  </target>
</project>

Eclipse should looks something like the screenshot below. Note the Ant icon on build.xml.

Step 2 Right-click on the root node in the project. - Select Properties - Select Builders - Select New - Select Ant Build - In the Main tab, complete the path to the build.xml file in the bin folder.

Check the Output

The Eclipse output window (named Console) should show the following after a build:

Buildfile: /home/<user>/src/Test/build.xml

CreateJar:
         [jar] Building jar: /home/<user>/src/Test/Test.jar
BUILD SUCCESSFUL
Total time: 152 milliseconds

这篇关于如何在Eclipse Java项目中自动生成.jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆