Ant Build - src不存在

时间:2016-12-04 05:03:49

标签: java apache ant jar build.xml

我正在创建一个build.xml文件,它将创建一个jar文件,这个jar文件应该运行我在清单中设置的主类..这里是代码,

<description>
    Create a Java Project (JAR) with Ant build script
</description>

<target name="init" description="Initializes properties">
    <echo message="initializing properties..." />
    <property name="src.dir" location="src" />
    <property name="build.dir" location="build" />
    <property name="project.name" value="TestMain" />
    <property name="build.dir" value="build" />
    <property name="classes.dir" value="${build.dir}/classes" />
</target>
<presetdef name="javac">
    <javac includeantruntime="false" />
</presetdef>

<target name="clean" description="delete the build directory" depends="init">
    <echo message="deleting temporary directory..." />
    <delete dir="${build.dir}" />
    <delete file="${project.name}.jar"/>
</target>

<target name="prepare" description="Creates the build and classes directories" depends="clean">
    <echo message="creating temporary directory..." />
    <mkdir dir="${classes.dir}" />
</target>

<target name="compile" description="Compiles the code" depends="prepare">
    <echo message="compiling codes..." />
    <javac srcdir="${src.dir}" destdir="${classes.dir}" />
</target>


<target name="jarfile" description="JARs the code" depends="compile">
    <echo message="creating jar file..." />
    <jar destfile="${project.name}.jar" basedir="${classes.dir}" includes="com/**"> 
        <manifest>
            <attribute name="Main-Class" value="com.java.apache.ant.TestMain" />
        </manifest>
    </jar>
</target>

我在目标:编译时遇到错误,表示 src不存在

Buildfile: C:\_GIT\ApacheAnt\deploy\build.xml
Trying to override old definition of task javac
init:
     [echo] initializing properties...
clean:
     [echo] deleting temporary directory...
   [delete] Deleting directory C:\_GIT\ApacheAnt\deploy\build
prepare:
     [echo] creating temporary directory...
    [mkdir] Created dir: C:\_GIT\ApacheAnt\deploy\build\classes
compile:
     [echo] compiling codes...

BUILD FAILED
C:\_GIT\ApacheAnt\deploy\build.xml:33: srcdir "C:\_GIT\ApacheAnt\deploy\src" does not exist!

这是我项目的结构

src
 |__com.... *.java

build
 |__com...*.class

deploy
 |__build.xml

当我检查在deploy文件夹中创建的build / classes文件夹时,没有* .class文件被复制..我的xml文件有什么问题吗?感谢

1 个答案:

答案 0 :(得分:0)

看起来,你的构建xml考虑“部署”作为项目的基础目录,导致“src”为“deploy / src”。请检查“project”标签中的“basedir”属性以正确设置。