2016-12-04 228 views
0

我創建一個build.xml文件,該文件將創建一個jar文件,這個jar文件應該運行的主類我在清單中設置..這裏是代碼,Ant構建 - SRC不存在

<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 

正如我檢查了,沒有* .class文件被複制部署文件夾內創建構建/ classes文件夾..我的XML文件中的任何問題的結構?謝謝

回答

0

看起來,您構建的xml將「deploy」視爲導致「src」爲「deploy/src」的項目的基本目錄。請在「project」標籤中檢查您的「basedir」屬性以正確設置它。