ANT编译失败



我是ANT的新手。我有以下项目结构,

      Project
        module1
          build.xml
        module2
          build.xml
        lib

实际情况是,我在模块2中配置了build.xml来构建一个模块2类的JAR,并将其放在lib文件夹中。现在,我从module1的build.xml调用module2的build.xml。module1需要module2的JAR进行编译。我可以在lib文件夹中看到JAR,但模块1仍然没有编译。有人能帮我吗?这里是我的build.xml文件,module1 build.xml,

<?xml version="1.0" encoding="UTF-8"?>

<property name="app.name" value="module1" />
<property name="src.home" value="${basedir}/src/main/java" />
<property name="build.home" value="${basedir}/build" />
<property name="ear.home" value="${basedir}/ear" />
<property name="module2.home" value="../module2" />
<property name="external.lib.dir" value="../lib" />
    <path id="lib.path">
    <fileset dir="${external.lib.dir}">
        <include name="*.jar" />
    </fileset>
</path>
<path id="module2.path">
    <filelist dir="${module2.home}" />
</path>

<target name="clean">
    <delete dir="${build.home}" />
    <delete dir="${ear.home}" />
</target>
<target name="prepare" depends ="clean"
    description="Create build dirs and copy static files to work dir">
    <mkdir dir="${build.home}" />
    <mkdir dir="${build.home}/classes" />
</target>

<target name="compile" depends="prepare"
    description="Compile Java sources and copy to build/classes dir">
    <javac includeantruntime="false" srcdir="${src.home}" destdir="${build.home}/classes">
        <classpath refid="lib.path" />
    </javac>
    <copy todir="${build.home}/classes">
        <fileset dir="${src.home}" excludes="**/*.java" />
    </copy>
</target>
<target name="includeJar">
    <subant target="buildJar">
        <fileset dir="../module2/" includes="build.xml" />
    </subant>
</target>
<target name="buildEar" depends="includeJar,compile">
            <jar destfile="${basedir}/ear/${app.name}.ear" basedir="${build.home}" />
</target>

这是module2build.xml,

<?xml version="1.0" encoding="UTF-8"?>
<project name="module2">    
<property name="app.name"      value="module2"/>
<property name="src.home"      value="${basedir}/src/main/java"/>
<property name="build.home" value="${basedir}/build"/>
<echo>
    module2 build.xml
</echo>
<target name="clean">
    <delete dir="${build.home}"/>
</target>
<target name="init" depends="clean"
          description="Create build dirs and copy static files to work dir">
    <mkdir  dir="${build.home}"/>
    <mkdir  dir="${build.home}/classes"/>      
  </target>

<target name="compile" depends="init"
          description="Compile Java sources and copy to build/classes dir">
    <javac includeantruntime="false" srcdir="${src.home}"
          destdir="${build.home}/classes">
    </javac>
    <copy  todir="${build.home}/classes">
      <fileset dir="${src.home}" excludes="**/*.java"/>
    </copy>
  </target>
<target name="buildJar" depends="compile">
    <echo>Inside buildJar of module2
            </echo>
    <jar destfile="../lib/${app.name}.jar"
         basedir="${build.home}"
         />
  </target>

模块1似乎没有编译,因为模块2创建的jar没有构建。

您正在调用subant任务,但没有指定目标:

<subant target="buildJar">
    <fileset dir="../module2/" includes="build.xml" />
</subant>

module1构建文件没有指定默认目标:

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

我建议的解决方案是指定一个默认目标如下:

<project name="module2" default="buildJar">    

旁白

多模块构建支持和依赖关系管理是现代Java构建工具中的特性。如果你想在ANT中构建一个大型项目,可以考虑学习ivy插件的工作原理。

解决了问题。我忽略了一个愚蠢的错误。以下是我所做的更改,module2的build.xml,1.我做了以下更改,将jar的basedir从basedir="${build.home}"更改为basedir="${build.home}/classes"module1的build.xml。2.对buildEar目标进行了如上所述的类似更改。我能够成功生成EAR:)

感谢Mark抽出时间:)

相关内容

  • 没有找到相关文章

最新更新