eclipse中的build.xml不构建jar

时间:2013-06-03 12:07:25

标签: java

在我们公司的Java和build.xml上有许多应该编译,清理和运行所有代码的项目,因此build.xml不会编译代码而.jar也不会创建。 的build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="java" basedir=".">

    <description>Builds, tests, and runs the project front_web.</description>
      <property name="project.location" value="C:\apache\repp_copy\Java\processing" />
      <property name="webapps.location" value="C:\apache-tomcat-6.0.36\webapps" />
       <path id="project.class.path">
        <pathelement location="C:\apache\repp_copy\Java\processing\lib\servlet-api.jar" />
        <pathelement location="C:\apache\repp_copy\Java\processing\lib\log4j-1.2.16.jar" />
        <pathelement location="C:\apache\repp_copy\Java\processing\lib\mailapi.jar" />
       </path>  
    <target name="compile" depends="clean">
            <javac  srcdir="src" destdir="Build/tnxBuild" debug="true" encoding="utf-8">
                <classpath refid="project.class.path" />
            </javac>
            <copy todir="Build/tnxBuild">
              <fileset dir="src">
                <include name="*.properties"/>
              </fileset>
            </copy>
    </target>

    <target name="compileMcVpc" depends="clean, compile">
        <javac  srcdir="module-thx/src" destdir="Build/tnxBuild" debug="true" encoding="utf-8">
            <classpath refid="project.class.path" />
        </javac>
        <copy todir="Build/tnxBuild">
          <fileset dir="module-thx/src">
            <include name="*.properties"/>
          </fileset>
        </copy>
    </target>

    <fileset id="common" dir="lib">
                <include name="*.jar" />
    </fileset>

    <target name="createJar" depends="compileMcVpc,clean,compile">  
    <war destfile="thx.jar" webxml="module-thx/web/WEB-INF/web.xml">
        <lib refid="common" />
        <classes dir="${project.location}/Build/tnxBuild">
        </classes>

        <metainf file="module-thx/web/META-INF/context.xml">
        </metainf>
        <fileset id="content" dir="${project.location}/module-thx/web">
            <include name="*/*.*" />
            <include name="*.*" />
        </fileset>          

    <!--<metainf file="front_web/web/META-INF/context.xml">
      </metainf>-->
        <!--<fileset id="content" dir=".">
            <include name="*.*" />
        </fileset>-->
    </war>  
    </target>   

    <target name="clean">
        <delete dir="Build/tnxBuild" />
        <mkdir dir="Build/tnxBuild" />  
    </target>

    <target name="runApp" depends="createJar">
        <delete dir="${webapps.location}/thx.jar" />
        <copyfile src="thx.jar" dest="C:\apache\repp_copy\Java\processing\jars\thx.jar" />
        <delete dir="thx.jar" />
    </target>
</project>

PS所有目录都是正确的,双重检查。 控制台的结果:

Buildfile: C:\apache\repp_copy\Java\processing\build-Tnx.xml
BUILD SUCCESSFUL
Total time: 422 milliseconds

1 个答案:

答案 0 :(得分:1)

查看为“createJar”目标列出的依赖项。

<target name="createJar" depends="compileMcVpc,clean,compile">

如果调用createJar目标,在运行之前,ant将按顺序调用compileMcVpc,clean和compile。

JAR任务读入在compileMcVpc期间构建的文件,然后通过clean删除。所以当createJar开始工作时,它所需的文件就不见了。

现在有一点有趣的是你有两个目标,compileMcVpc,它们都将java字节码输出到同一个目录。鉴于你的目标的顺序,我希望“src”类将在JAR中,而不是“module-thx / source”jar。

尝试理顺您的依赖项。为了简化和调试,可以直接按照您希望它们运行的​​顺序删除所有依赖项,而无需为您执行此操作。如果这样可行,则证明依赖性是错误的。

相关问题