java Apache Ant{Compile javac srcdir}不存在
我是ApacheAnt新手,目前正在从事ApacheAnt项目。我刚开始,将项目导入工作区并尝试运行构建。xml。我将原始项目附带的所有库添加到构建路径中。我有以下问题。请别人写代码,我应该改进它。所有这些目录都存在于项目目录中
BUILD FAILED
C:\workspace\MyApp\build.xml:83: srcdir "C:\workspace\MyApp\${compile.javac.srcdir}" does not exist!
错误代码引用了生成的以下部分。xml文件
<target name="compile.default" depends="init">
<javac fork="yes" srcdir="${compile.javac.srcdir}" destdir="${compile.javac.destdir}" includes="${compile.javac.include}" excludes="${compile.javac.exclude}" classpath="${compile.javac.classpath}" debug="${compile.javac.debug}" optimize="${compile.javac.optimize}" deprecation="${compile.javac.deprecation}" verbose="${compile.javac.verbose}">
</javac>
<copy todir="${compile.javac.destdir}">
<fileset dir="${compile.javac.srcdir}" includes="${compile.copy.include}" excludes="${compile.copy.exclude}"/>
</copy>
</target>
<target name="compile" depends="init,compile.default" description="Compile all java source">
</target>
<!--+++++++++++++++-->
<!-- lib target(s) -->
<!--+++++++++++++++-->
<target name="lib.default" depends="init,compile">
<xmlbean schema="config/schemas/validate/1.0/validate.xsd" destfile="lib/glx-beans.jar" classpath="lib/xbean.jar:lib/jsr173_1.0_api.jar" />
<jar jarfile="${lib.filename}">
<fileset dir="${lib.srcdir}" excludes="${lib.exclude}" />
</jar>
</target>
<target name="lib" depends="init,compile,lib.default" description="Create all Project Libraries">
</target>
你能告诉我我错过了什么吗
# 1 楼答案
未定义
${compile.javac.srcdir}
。有几种可能性:build.xml
中定义的,而是在某种属性文件中定义的。查看构建脚本中是否有类似<property file="..."/>
的内容。我的建议是在build.xml
文件中定义所有属性,并使用属性文件覆盖这些设置。这样,开发人员只需要在build.xml
文件中创建一个构建文件,而不必担心设置一个单独的build.porperties
文件李>build.xml
文件中定义的,但您忘了说您使用它的目标依赖于此任务李>您可以做的一件事是在运行Ant时使用
-d
参数。在使用-d
参数运行Ant时,我运行以下命令:然后我可以查看
ant.out
,看看我是否不知何故没有定义那个特定的属性。可能是我的大写字母写错了,或者是物业名称拼错了。例如,我很可能会将属性定义为copmile。javac。因为我不知道怎么拼写。查看-d
输出可以快速指出这些类型的错误顺便说一句,你不应该让所有的任务都依赖于
init
,因为它们无论如何都依赖于compile.default
:如果我运行目标
lib
,它将看到compile
依赖于compile.default
,而init
依赖于compile.default
。因此,您的构建将运行init
,然后compile.default
,然后compile
,然后是'lib'。默认的and finally
lib`如果init任务只是设置属性,那么可以在任何任务之外进行设置。然后,将在执行任何任务之前设置这些属性。这样,他们就不会被遗忘。如果您的
init
也在创建目录,您可能希望将这些<mkdir/>
任务移动到使用该目录的任务前面。例如,您可能希望在<javac/>
任务之前在javac
中使用destdir我发现在任何任务之外分配默认属性,并在需要简化
build.xml
之前创建目录。另外,如果用户只是编译而不是打包jar/war/etc,就不会创建一整群未使用的目录