I have been adapting this suggested code for making a war file, and have created the following contents of the BuildWar.xml file show in the image above:
我一直在调整这个建议的代码来制作war文件,并在上图中创建了BuildWar.xml文件的以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject" default="default">
<target name="default" depends="setup,compile,buildwar,deploy"></target>
<target name="setup">
<mkdir dir="dist" />
<echo>Copying web into dist</echo>
<copydir dest="dist/web" src="web" />
<copydir dest="dist/web/WEB-INF/lib" src="${basedir}/../web/WEB-INF/lib" />
</target>
<target name="compile">
<delete dir="${dist.dir}/web/WEB-INF/classes" />
<mkdir dir="${dist.dir}/web/WEB-INF/classes" />
<javac destdir="${dist.dir}/web/WEB-INF/classes" srcdir="src">
<classpath>
<fileset dir="${basedir}/myapp/web/WEB-INF/lib">
<include name="*" />
</fileset>
</classpath>
</javac>
<copy todir="${dist.dir}/web/WEB-INF/classes">
<fileset dir="src">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="buildwar">
<war basedir="${basedir}/dist/web" destfile="My.war"
webxml="${basedir}/dist/web/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="${basedir}/dist/web/WEB-INF/">
<include name="**/*.jar" />
</webinf>
</war>
</target>
<target name="deploy">
<copy file="My.war" todir="${tomcat.deploydir}" />
</target>
</project>
Running the above code as an ant buildfile in eclipse produces some warnings that copydir has been deprecated, and also produces the following error message:
在eclipse中将上述代码作为ant构建文件运行会产生一些警告,表示不推荐使用copydir,并且还会产生以下错误消息:
BUILD FAILED
C:\mypath\myapp\BuildWar.xml:10: srcdir C:\mypath\web\WEB-INF\lib does not exist!
However, when I replace the .. in line 10 with myapp, I get an error message saying that
但是,当我用myapp替换第10行中的..时,我收到一条错误消息
BUILD FAILED
C:\mypath\myapp\BuildWar.xml:10: srcdir C:\mypath\myapp\myapp\web\WEB-INF\lib does not exist!
How do I fix the code so that it no longer gives the BUILD FAILED message?
如何修复代码以使其不再提供BUILD FAILED消息?
2 个解决方案
#1
1
I think the line:
我认为这一行:
<copydir dest="dist/web/WEB-INF/lib" src="${basedir}/../web/WEB-INF/lib" />
should just be:
应该只是:
<copydir dest="dist/web/WEB-INF/lib" src="${basedir}/web/WEB-INF/lib" />
${basedir} refers to C:\mypath\myapp, if that is where Ant is run from (or where BuildWar.xml lives)
$ {basedir}指的是C:\ mypath \ myapp,如果这是从哪里运行Ant(或者BuildWar.xml所在的位置)
#2
1
Declare it right at the top as an attribute of the project tag.
在顶部将其声明为项目标记的属性。
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="C:\......." name="myproject" default="default">
<target name="default" depends="setup,compile,buildwar,deploy"></target>
<target name="setup">
<mkdir dir="dist" />
<echo>Copying web into dist</echo>
<copydir dest="dist/web" src="web" />
<copydir dest="dist/web/WEB-INF/lib" src="${basedir}/../web/WEB-INF/lib" />
</target>
<target name="compile">
<delete dir="${dist.dir}/web/WEB-INF/classes" />
<mkdir dir="${dist.dir}/web/WEB-INF/classes" />
<javac destdir="${dist.dir}/web/WEB-INF/classes" srcdir="src">
<classpath>
<fileset dir="${basedir}/myapp/web/WEB-INF/lib">
<include name="*" />
</fileset>
</classpath>
</javac>
<copy todir="${dist.dir}/web/WEB-INF/classes">
<fileset dir="src">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="buildwar">
<war basedir="${basedir}/dist/web" destfile="My.war"
webxml="${basedir}/dist/web/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="${basedir}/dist/web/WEB-INF/">
<include name="**/*.jar" />
</webinf>
</war>
</target>
<target name="deploy">
<copy file="My.war" todir="${tomcat.deploydir}" />
</target>
</project>
After you declare the base dir write all paths relative to basedir.
声明基础目录后,写入相对于basedir的所有路径。
#1
1
I think the line:
我认为这一行:
<copydir dest="dist/web/WEB-INF/lib" src="${basedir}/../web/WEB-INF/lib" />
should just be:
应该只是:
<copydir dest="dist/web/WEB-INF/lib" src="${basedir}/web/WEB-INF/lib" />
${basedir} refers to C:\mypath\myapp, if that is where Ant is run from (or where BuildWar.xml lives)
$ {basedir}指的是C:\ mypath \ myapp,如果这是从哪里运行Ant(或者BuildWar.xml所在的位置)
#2
1
Declare it right at the top as an attribute of the project tag.
在顶部将其声明为项目标记的属性。
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="C:\......." name="myproject" default="default">
<target name="default" depends="setup,compile,buildwar,deploy"></target>
<target name="setup">
<mkdir dir="dist" />
<echo>Copying web into dist</echo>
<copydir dest="dist/web" src="web" />
<copydir dest="dist/web/WEB-INF/lib" src="${basedir}/../web/WEB-INF/lib" />
</target>
<target name="compile">
<delete dir="${dist.dir}/web/WEB-INF/classes" />
<mkdir dir="${dist.dir}/web/WEB-INF/classes" />
<javac destdir="${dist.dir}/web/WEB-INF/classes" srcdir="src">
<classpath>
<fileset dir="${basedir}/myapp/web/WEB-INF/lib">
<include name="*" />
</fileset>
</classpath>
</javac>
<copy todir="${dist.dir}/web/WEB-INF/classes">
<fileset dir="src">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="buildwar">
<war basedir="${basedir}/dist/web" destfile="My.war"
webxml="${basedir}/dist/web/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="${basedir}/dist/web/WEB-INF/">
<include name="**/*.jar" />
</webinf>
</war>
</target>
<target name="deploy">
<copy file="My.war" todir="${tomcat.deploydir}" />
</target>
</project>
After you declare the base dir write all paths relative to basedir.
声明基础目录后,写入相对于basedir的所有路径。