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

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

问题描述

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

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

如何在此项目中进行设置以确保在重新编译项目中的 .java 文件之一时更新此 .jar 文件?

谢谢.

推荐答案

创建一个 Ant 文件并告诉 Eclipse 来构建它.只有两个步骤,按照下面的分步说明,每个步骤都很容易.

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.

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

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 应该类似于下面的屏幕截图.请注意 build.xml 上的 Ant 图标.

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

第 2 步右键单击项目中的根节点.- 选择属性- 选择建设者- 选择新建- 选择 Ant Build- 在 Main 选项卡中,填写 bin 文件夹中 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.

检查输出

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

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天全站免登陆