我一直在改编this suggested code 用于制作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>
在 eclipse 中将上述代码作为 ant buildfile 运行会产生一些警告,指出 copydir 已被弃用,并且还会产生以下错误消息:
BUILD FAILED
C:\mypath\myapp\BuildWar.xml:10: srcdir C:\mypath\web\WEB-INF\lib does not exist!
但是,当我将第 10 行中的 .. 替换为 myapp 时,我收到一条错误消息,指出
BUILD FAILED
C:\mypath\myapp\BuildWar.xml:10: srcdir C:\mypath\myapp\myapp\web\WEB-INF\lib does not exist!
如何修复代码,使其不再显示 BUILD FAILED 消息?
最佳答案
我认为行:
应该只是:
${basedir} 指的是 C:\mypath\myapp,如果这是运行 Ant 的地方(或者 BuildWar.xml 所在的地方)
关于java - 从 eclipse web 项目创建 war 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18260003/