ot;${dist.dir}/${webAppName}"/>
</war>
</target>
</project>
对照着Maven+Ant打包的流程图看这个build.xml文件,一点也不难看懂,就一个过程化的批处理脚本而己。
关键在于:
<path id="maven-ant-tasks.classpath" path="C:/ant/lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant"
classpathref="maven-ant-tasks.classpath" />
<artifact:pom id="maven.project" file="pom.xml" />
<artifact:dependencies filesetId="deps.fileset.compile" useScope="compile">
<!--<pom file="pom.xml"/>-->
<pom refid="maven.project" />
</artifact:dependencies>
<path id="compile.classpath">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<target name="download-libs" depends="clean">
<copy todir="${lib.dir}">
<fileset refid="deps.fileset.compile" />
<mapper type="flatten" />
</copy>
</target>
此处声明了:
1) 我们在ant的build.xml文件中使用maven插件
2) 我们的工程所用到的依赖库即所有的.jar文件在工程(myssh2)原有工程的pom.xml文件中已经声明过依赖关系了,build.xml文件只要使用它就可以了。
3) 我们的ant在使用javac进行编译时所需的库在${lib.dir},见build.properties即在c:\eclipsespace\myssh2\lib目录内。
4) c:\eclipsespace\myssh2\lib目录内所有的jar则是通过“download-libs”这个target得来的。
下面是build.xml文件被运行后的输出效果即在eclipse中打开build.xml文件后右键选RunAs->Ant Build的输出:
去我们的工程的dist目录下查看,就可以看到一个myssh2.war工程
把这个工程直接扔到tomcat的webapp目录下,运行tomcat后登录http://localhost:8080/myss2后一切正常,结束本天的教程。
PS:
一般我不喜欢把一个.war包扔到tomcat下去,而是喜欢把符合war目录结构的这样的一个目录扔到tomcat的webapp目录下,直到这个工程成品了,即通过测试后再打成war包以便于tomcat或者是weblogic、WAS的布署,因此对于我来说在<target name=”compile”depends=”download-libs”>这步完成后就够用了。