Java Ant 构建失败:“目标“build..xml”不存在”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1086449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ant build failed: "Target "build..xml" does not exist"
提问by
When I run the ant file in verbose mode, I got an error like the one below. Does anyone have any ideas what is going wrong? I am new to this
当我以详细模式运行 ant 文件时,出现如下错误。有谁知道出了什么问题?我是新来的
antlib:org.apache.tools.ant] Could not load definitions from resource org/apach
e/tools/ant/antlib.xml. It could not be found.
Override ignored for property "java.home"
BUILD FAILED
Target "build.xml" does not exist in the project "MYPROJECT".
at org.apache.tools.ant.Project.tsort(Project.java:1821)
at org.apache.tools.ant.Project..topoSort(Project.java:1729)
at org.apache.tools.ant.Project.topoSort(Project.java:1692)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:698)
at org.apache.tools.ant.Main.startAnt(Main.java:199)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Total time: 1 second
This is my build.xml
:
这是我的build.xml
:
<project name="MYPROJECT" default="dev" basedir=".">
<property name="build.home" value="build/jsp" />
<property name="tomcat.home" location="../Tomcat 5.0/" />
<path id="project.class.path">
<fileset dir="./lib/">
<include name="**/*.jar" />
</fileset>
</path>
<target name="reltag">
<tstamp>
<format property="now" pattern="d MMM yyyy HH:mm" />
</tstamp>
<property name="reltag" value="Built date: ${now}" />
</target>
<target name="dev" depends="compile" description="Builds for development">
<mkdir dir="jsp/WEB-INF/lib" />
<mkdir dir="jsp/WEB-INF/classes" />
<copy todir="jsp/WEB-INF/lib">
<fileset dir="lib">
<exclude name="**/CVS/*" />
</fileset>
</copy>
<copy todir="jsp/WEB-INF/classes">
<fileset dir="classes">
<exclude name="**/CVS/*" />
</fileset>
</copy>
</target>
<target name="compile" depends="myproject-gen,reltag">
<copy file="setup/Version.java.template" tofile="java/myproject/Version.java" overwrite="true">
<filterset>
<filter token="VERSION" value="${reltag}" />
</filterset>
</copy>
<mkdir dir="classes" />
<depend srcdir="java" destdir="classes" cache="depcache" />
<javac srcdir="java" destdir="classes">
<classpath refid="project.class.path" />
</javac>
</target>
<target name="myproject-gen" description="Generates torque classes and SQL for myproject">
<!-- generate the java files -->
<ant dir="torque" target="om" />
<antcall target="myproject-sql-mysql" />
</target>
<!-- generate the schema.sql script for MySQL -->
<target name="myproject-sql-mysql" depends="myproject-sql-mysql-check" unless="mysql.schema.up.to.date">
<echo message="Generating SQL file for MySQL" />
<ant dir="torque" target="sql">
<property name="torque.database" value="mysql" />
<property name="torque.runOnlyOnSchemaChange" value="false" />
</ant>
<move file="sql/gen/myproject-schema.sql" tofile="sql/gen/myproject-schema-mysql.sql" overwrite="true" />
<copy file="sql/gen/myproject-schema-mysql.sql" tofile="jsp/admin/database.sql" overwrite="true" />
<copy file="sql/init.sql" tofile="jsp/admin/init.sql" overwrite="true" />
</target>
<!-- check if we need to generate the sql file -->
<target name="myproject-sql-mysql-check">
<uptodate property="mysql.schema.up.to.date" targetfile="sql/gen/myproject-schema-mysql.sql" srcfile="torque/myproject-schema.xml" />
</target>
<target name="myproject-war" depends="compile-jsp">
<mkdir dir="build" />
<jar destfile="build/myproject.war" basedir="build/jsp" />
</target>
<target name="prepare_for_war_file">
<mkdir dir="build\jsp-classes\org\apache\jsp" />
<!-- <move todir="${build.home}/WEB-INF/classes/org/apache/jsp"> <fileset dir="${build.home}"> <include name="*.jsp"/> </fileset> </move> -->
<!-- copy everything which is not a jsp to admin directory -->
<copy tofile="${build.home}/admin/database.sql">
<fileset file="sql/gen/*-schema-mysql.sql" />
</copy>
<copy file="sql/init.sql" todir="${build.home}/admin" />
<mkdir dir="${build.home}/pdb_files" />
<!-- copy images directory -->
<copy todir="${build.home}/images">
<fileset dir="jsp/images" />
</copy>
<copy todir="${build.home}/hand">
<fileset dir="jsp/hand" />
</copy>
<!-- copy javascript directory -->
<copy todir="${build.home}/javascript">
<fileset dir="jsp/javascript" />
</copy>
<!-- copy META-INF directory -->
<copy todir="${build.home}/META-INF">
<fileset dir="jsp/META-INF" />
</copy>
<!-- copy stylesheet directory -->
<copy todir="${build.home}/stylesheet">
<fileset dir="jsp/stylesheet" />
</copy>
<!-- copy WEB-INF directory -->
<copy todir="${build.home}/WEB-INF/classes/">
<fileset dir="classes/" includes="**" />
</copy>
<copy todir="${build.home}/WEB-INF/lib">
<fileset dir="lib" includes="*.*" excludes="Cabwiz" />
</copy>
<!-- copy license and properties -->
<!--<copy file="WebContent/myproject.license" todir="${build.home}"/> -->
<copy file="jsp/myproject.properties" todir="${build.home}" />
<!-- move jsp classes to the correct package structure so war file will work when deployed -->
<move todir="${build.home}/WEB-INF/classes/org/apache/jsp">
<fileset dir="${build.home}" includes="**/*.class" excludes="WEB-INF/**" />
</move>
<antcall target="create-web_XML"></antcall>
</target>
<target name="create-web_XML">
<loadfile property="generated.web.xml" srcFile="jsp/WEB-INF/generated_web.xml" />
<copy file="jsp/WEB-INF/web_template.xml" tofile="jsp/WEB-INF/web.xml.deployable" overwrite="true">
<filterset begintoken="<!--" endToken="-->">
<filter token="GENERATED_WEB_XML" value="${generated.web.xml}" />
</filterset>
</copy>
<copy file="jsp/WEB-INF/web.xml.deployable" tofile="build/jsp/WEB-INF/web.xml" />
</target>
<target name="compile-jsp" depends="dev">
<antcall target="prepare_for_war_file"></antcall>
<property environment="env" />
<taskdef classname="org.apache.jasper.JspC" name="jasper2">
<classpath id="jspc.classpath">
<pathelement location="${java.home}/../lib/tools.jar" />
<fileset dir="${env.tomcat.home}/bin2">
<include name="*.jar" />
</fileset>
<fileset dir="${env.tomcat.home}/server/lib">
<include name="*.jar" />
</fileset>
<fileset dir="${env.tomcat.home}/common/lib">
<include name="*.jar" />
</fileset>
</classpath>
</taskdef>
<mkdir dir="java/jsp-src" />
<jasper2 validateXml="false" package="org.apache.jsp" uriroot="jsp" webXmlFragment="jsp/WEB-INF/generated_web.xml" outputDir="java/jsp-src" />
<jspc srcdir="jsp" destdir="java/jsp-src">
<include name="include/**/*.jsp" />
<include name="**/*.jsp" />
</jspc>
<mkdir dir="build/jsp-classes" />
<property environment="env" />
<javac destdir="build/jsp/WEB-INF/classes" optimize="off" debug="on" failonerror="true" srcdir="java/jsp-src" excludes="**/*.smap">
<classpath>
<pathelement location="classes" />
<fileset dir="lib">
<include name="*.jar" />
</fileset>
<pathelement location="${env.tomcat.home}/common/classes" />
<fileset dir="${env.tomcat.home}/common/lib">
<include name="*.jar" />
</fileset>
<pathelement location="${env.tomcat.home}/shared/classes" />
<fileset dir="${env.tomcat.home}/shared/lib">
<include name="*.jar" />
</fileset>
<fileset dir="${env.tomcat.home}/bin">
<include name="*.jar" />
</fileset>
</classpath>
<include name="**" />
<!--<exclude name="**/includes/*menu_jsp.java" /> -->
</javac>
</target>
<target name="clean" description="Deletes the java/classes dir and torque base objects">
<delete dir="classes" />
<delete dir="${build.home}" />
<delete>
<fileset file="build/*" />
</delete>
<delete dir="java/myproject/torque/map" />
<delete dir="java/jsp-src" />
<delete dir="jsp/WEB-INF/classes" />
<delete dir="jsp/WEB-INF/lib" />
<delete>
<fileset dir="java/myproject/torque" includes="Base*.java" />
</delete>
<touch file="torque/myproject-schema.xml" />
</target>
</project>
回答by wheleph
- Probably you don't have environment variable ANT_HOME set properly
- It seems that you are calling Ant like this: "ant build..xml". If your ant script has name build.xml you need to specify only a target in command line. For example: "ant target1".
- 可能您没有正确设置环境变量 ANT_HOME
- 似乎您是这样调用 Ant 的:“ant build..xml”。如果您的 ant 脚本名称为 build.xml,您只需在命令行中指定一个目标。例如:“蚂蚁目标1”。
回答by Mnementh
Looks like you called it 'ant build..xml'. ant automatically choose a file build.xml in the current directory, so it is enough to call 'ant' (if a default-target is defined) or 'ant target' (the target named target will be called).
看起来您称它为“ant build..xml”。ant 会自动选择当前目录下的 build.xml 文件,因此调用“ant”(如果定义了默认目标)或“ant target”(将调用名为 target 的目标)就足够了。
With the call 'ant -p' you get a list of targets defined in your build.xml.
通过调用“ant -p”,您将获得在 build.xml 中定义的目标列表。
Edit:In the comment is shown the call 'ant -verbose build.xml'. To be correct, this has to be called as 'ant -verbose'. The file build.xml in the current directory will be used automatically. If it is needed to explicitly specify the buildfile (because it's name isn't build.xml for example), you have to specify the buildfile with the '-f'-option: 'ant -verbose -f build.xml'. I hope this helps.
编辑:在评论中显示了调用“ant -verbose build.xml”。正确地说,这必须称为“ant -verbose”。将自动使用当前目录中的 build.xml 文件。如果需要显式指定构建文件(例如,因为它的名称不是 build.xml),则必须使用“-f”选项指定构建文件:“ant -verbose -f build.xml”。我希望这有帮助。
回答by duracell
since your ant file's name is build.xml, you should just type ant without ant build.xml.
that is: > ant
[enter]
因为您的 ant 文件的名称是 build.xml,所以您应该只键入 ant 而没有 ant build.xml。即:> ant
[输入]
回答by David W.
Is this a problem Onlywhen you run ant -d or ant -verbose, but works other times
?
这是只有在您运行时才有问题ant -d or ant -verbose, but works other times
吗?
I noticed this error message line:
我注意到此错误消息行:
Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
The org/apache/tools/ant/antlib.xml
fileis embedded in the ant.jar
. The ant
command is really a shell script called ant
or a batch script called ant.bat
. If the environment variable ANT_HOME is not set, it will figure out where it's located by looking to see where the ant
command itself is located.
该org/apache/tools/ant/antlib.xml
文件嵌入在ant.jar
. 该ant
命令实际上是一个名为 .shell 脚本ant
或批处理脚本ant.bat
。如果未设置环境变量 ANT_HOME,它将通过查看ant
命令本身所在的位置来确定它所在的位置。
Sometimes I've seen this where someone will move the ant
shell/batch script to put it in their path, and have ANT_HOME either not set, or set incorrectly.
有时我看到有人会移动ant
shell/batch 脚本以将其放在他们的路径中,并且 ANT_HOME 要么没有设置,要么设置不正确。
What platform are you on? Is this Windows or Unix/Linux/MacOS? If you're on Windows, check to see if %ANT_HOME% is set. If it is, make sure it's the right directory. Make sure you have set your PATH to include %ANT_HOME%/bin
.
你在什么平台?这是 Windows 还是 Unix/Linux/MacOS?如果您使用的是 Windows,请检查是否设置了 %ANT_HOME%。如果是,请确保它是正确的目录。确保您已将 PATH 设置为 include %ANT_HOME%/bin
。
If you're on Unix, don't copy the ant shell script to an executable directory. Instead, make a symbolic link. I have a directory called /usr/local/bin
where I put the command I want to override the commands in /bin
and /usr/bin
. My Ant is installed in /opt/ant-1.9.2
, and I have a symbolic link from /opt/ant-1.9.2
to /opt/ant
. Then, I have symbolic links from all commands in /opt/ant/bin
to /usr/local/bin
. The Ant shell script can detect the symbolic links and find the correct Ant HOME location.
如果您使用的是 Unix,请不要将 ant shell 脚本复制到可执行目录。相反,建立一个符号链接。我有一个名为的目录/usr/local/bin
,我在其中放置了我想要覆盖的命令/bin
和 中的命令/usr/bin
。我的 Ant 安装在 中/opt/ant-1.9.2
,并且我有一个从/opt/ant-1.9.2
到的符号链接/opt/ant
。然后,我有所有命令的符号链接/opt/ant/bin
到/usr/local/bin
. Ant shell 脚本可以检测符号链接并找到正确的 Ant HOME 位置。
Next, go to your Ant installation directory and look under the lib directory to make sure ant.jar
is there, and that it contains org/apache/tools/ant/antlib.xml
. You can use the jar tvf ant.jar
command. The only thing I can emphasize is that you do have everything setup correctly. You have your Ant shell script in your PATH either because you included the bin directory of your Ant's HOME directory in your classpath, or (if you're on Unix/Linux/MacOS), you have that file symbolically linked to a directory in your PATH.
接下来,转到您的 Ant 安装目录并在 lib 目录下查看以确保ant.jar
在那里,并且它包含org/apache/tools/ant/antlib.xml
. 您可以使用该jar tvf ant.jar
命令。我唯一可以强调的是,您确实已正确设置了所有内容。您的 PATH 中有您的 Ant shell 脚本,要么是因为您在类路径中包含了 Ant 主目录的 bin 目录,要么(如果您使用的是 Unix/Linux/MacOS),您将该文件以符号方式链接到您的目录中小路。
Make sure your JAVA_HOME is set correctly (on Unix, you can use the symbolic link trick to have the java
command set it for you), and that you're using Java 1.5 or higher. Java 1.4 will no longer work with newer versions of Ant.
确保您的 JAVA_HOME 设置正确(在 Unix 上,您可以使用符号链接技巧让java
命令为您设置它),并且您使用的是 Java 1.5 或更高版本。Java 1.4 将不再适用于较新版本的 Ant。
Also run ant -version
and see what you get. You might get the same error as before which leads me to think you have something wrong.
也运行ant -version
,看看你得到了什么。您可能会遇到与之前相同的错误,这让我认为您有问题。
Let me know what you find, and your OS, and I can give you directions on reinstalling Ant.
让我知道您找到了什么,以及您的操作系统,我可以为您提供重新安装 Ant 的指导。
回答by abilasco
I'm probably late but this worked for me:
我可能迟到了,但这对我有用:
- Open your build.xml file located in your project's directory.
- Copy and Paste the following code in the main projecttag :
<target name="build" />
- 打开位于项目目录中的 build.xml 文件。
- 将以下代码复制并粘贴到主项目标签中:
<target name="build" />
回答by Ranjith Venkatesh
in the folder where the build.xml resides run command only -
在 build.xml 所在的文件夹中仅运行命令 -
ant
蚂蚁
and not the command - `
而不是命令 - `
ant build.xml
蚂蚁构建.xml
`
`
. if you are using the ant file as build xml then the below steps helps you Steps : open cmd Prompt >> switch to the project location >>type ant and click enter key
. 如果您使用 ant 文件作为构建 xml,那么以下步骤可以帮助您 步骤:打开 cmd Prompt >> 切换到项目位置 >> 键入 ant 并单击 Enter 键