【问题标题】:.jar not being created after ANT build in Eclipse在 Eclipse 中构建 ANT 后未创建 .jar
【发布时间】:2020-05-12 07:17:22
【问题描述】:

由于某种原因,当我 ANT 运行我的 build.xml 文件时,Eclipse 没有创建 .jar 文件。

请考虑我的代码:

<!-- language: lang-xml -->

<project default="deploy">

    <!-- user.home is C:\Documents and Settings\<user name> or C:\Users\<user 
        name> (Windows) or /Users/<user name> (Mac OSX) -->
    <property name="ext.dir"
        value="${user.home}/MotiveWave Extensions" />
    <property name="dev.dir" value="${ext.dir}/dev" />
    <property name="jar.dir" value="${ext.dir}/jar" />
    <property name="src.dir" value="../src/" />
    <property name="bin.dir" value="../bin/" />
    <property name="lib.dir" value="../lib/" />

    <!-- Name of the jar file (created in the 'jar' target) -->
    <property name="jar.name" value="example15" />

    <!-- removes all files generated by the build process -->
    <target name="clean">
        <!-- <delete dir="classes"/> <delete dir="jar"/> -->
    </target>


    <!-- Compiles the source putting the generated class files in the 'classes' 
        subdirectory. -->
    <target name="compile" depends="clean">
        <mkdir dir="classes" />
        <javac includeantruntime="false" srcdir="${src.dir}"
            destdir="classes" debug="true" debuglevel="lines,source">
            <classpath refid="classpath" />
        </javac>
    </target>

    <!-- Creates a jar file (for distribution). -->
    <target name="jar" depends="compile">
        <!-- <delete dir="jar"/> -->
        <jar destfile="${ext.dir}/jar/${jar.name}.jar"
            manifest="Manifest.MF" level="9">
            <fileset dir="classes" includes="**/*.class" />
            <fileset dir="${src.dir}" includes="**/*.properties" />
            <!-- Uncomment the following line to include the source in the jar file. -->
            <fileset dir="${src.dir}" includes="**/*.java" />
        </jar>
    </target>

    <!-- Creates and deploys the jar file to the extensions directory. This 
        is the default task. -->
    <target name="deploy_jar" depends="jar">
        <!-- We will place this jar file in a 'lib' directory. -->
        <mkdir dir="${ext.dir}/jar" />
        <copy file="jar/${jar.name}.jar" todir="${ext.dir}/jar"
            overwrite="true" />
        <!-- This tells MotiveWave to check for any modified files and load them. -->
        <touch file="${ext.dir}/.last_updated" />
    </target>

    <!-- This alternative deployment task, copies all class and properties files 
        to the extensions directory (instead of creating the jar file). -->
    <target name="deploy" depends="compile">
        <!-- Copy all .class and .properties files. These files are placed in a 
            subdirectory called 'dev' in the extensions directory. This directory is 
            first deleted in case you have moved or renamed any of the files. -->
        <delete dir="${dev.dir}" />
        <mkdir dir="${dev.dir}" />
        <mkdir dir="${jar.dir}" />
        <!-- <copy todir="${dev.dir}" overwrite="true"> <fileset dir="classes" 
            includes="**/*.class"/> <fileset dir="${src.dir}" includes="**/*.properties"/> 
            </copy> -->
        <!-- This tells MotiveWave to check for any modified files and load them. -->
        <touch file="${ext.dir}/.last_updated" />
    </target>

    <!-- This class path includes all of the jars in the lib directory. -->
    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar" />
        <pathelement path="classes" />
    </path>
</project>

/build/classes/study_examples 目录中的文件显示得很好(所以我相信“干净”和“编译”部分工作正常) 目录 /jar 正在按预期在 Users/MotiveWave/Extensions 中创建。

但我找不到一个我定义的名称的 .jar 文件(“示例 15”)(所以“目标名称 'jar' 不知何故有问题)

谁能解释为什么会这样?

【问题讨论】:

  • 你在运行什么目标?默认的“部署”目标不依赖于“jar”

标签: java eclipse build ant


【解决方案1】:

你可以替换

<jar destfile="${ext.dir}/jar/${jar.name}.jar" manifest="Manifest.MF" level="9">

<jar destfile="${jar.dir}/${jar.name}.jar" manifest="Manifest.MF" level="9">

但是,它不会解决您的问题。为了解决这个问题,替换

<target name="deploy" depends="compile">

<target name="deploy" depends="deploy_jar">

【讨论】:

猜你喜欢
  • 2012-07-10
  • 2014-07-23
  • 2014-02-10
  • 2015-03-06
  • 1970-01-01
  • 1970-01-01
  • 2016-03-13
  • 1970-01-01
  • 2013-06-23
相关资源
最近更新 更多