在 Netbeans 中,经过一些研究,我设法编辑文件 build.xml 以自定义 IDE 生成我的 jar 和 list 文件的方式。我不得不为 Eclipse 迁移一个项目,甚至找到了构建 jar 的选项,但我需要使用一些个性化信息构建我的 jar。
我在 eclipse 的项目中将文件 build.xml 作为构建文件 ANT 添加,但是当我发送执行它时,eclipse 运行两次,一次生成 2 个 jars 文件。
按照我的文件build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="GerOficios" default="makejar" basedir='.'>
<target name="makejar">
<property file="version_info.properties" />
<property name="application.title" value="GerOficios_v6" />
<property name="main.class" value="com/dfmachado/geroficios/View/ListaDeOficiosUI" />
<buildnumber file="build.num" />
<property name="build.version.num" value="${version.number}.${build.number}" />
<tstamp>
<format property="TODAY" pattern="dd/MM/yyyy - HH:mm:ss" />
</tstamp>
<property name="store.jar.name" value="GerOficios ${build.version.num}" />
<property name="store.dir" value="store" />
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar" />
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}" />
<mkdir dir="${store.dir}" />
<jar destfile="${store.dir}/temp_final.jar" basedir="bin" filesetmanifest="skip">
<zipgroupfileset dir="lib" includes="*.jar" />
<manifest>
<attribute name="Main-Class" value="${main.class}" />
<attribute name="SplashScreen-Image" value="com/dfmachado/geroficios/View/image/minerva.png" />
<attribute name="Build-OS" value="${os.name} version ${os.version} on ${os.arch}" />
<attribute name="Java-Version" value="${javac.source}" />
<attribute name="Implementation-Title" value="${application.title}" />
<attribute name="Implementation-Version" value="${build.version.num}" />
<attribute name="Built-By" value="${user.name}" />
<attribute name="Built-Date" value="${TODAY}" />
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar" excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA" />
</zip>
<delete file="${store.dir}/temp_final.jar" />
</target>
</project>
只是指出,eclipse 生成一个 jar 的方式与它在 netbeans 中生成的方式相同,问题是 ANT 运行两次并生成 2 个 jar,即使我只给出一次命令,如下面的打印所示:
在同一项目中通过命令行运行 ant,但只创建了一个文件,显然问题出在 eclipse 中的某些配置,但到目前为止我还没有找到。
最佳答案
ANT 是您在项目构建器中添加的构建器。请在这里查看:
Project -> Right Click -> Properties -> Builders
您可以将它与 Eclipse 的工作区设置为“自动构建”一起启用 - 这将触发自动构建。
或者,您可以从构建器列表中取消选择构建器并在需要时手动运行它!
关于java - Eclipse 运行 ANT 两次,甚至只发送运行一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40633385/