在我们公司中,许多关于 Java 的项目和一个 build.xml 应该编译、清理和运行所有代码,所以 build.xml 不编译代码,.jar 也不创建。构建.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="java" basedir=".">
<description>Builds, tests, and runs the project front_web.</description>
<property name="project.location" value="C:\apache\repp_copy\Java\processing" />
<property name="webapps.location" value="C:\apache-tomcat-6.0.36\webapps" />
<path id="project.class.path">
<pathelement location="C:\apache\repp_copy\Java\processing\lib\servlet-api.jar" />
<pathelement location="C:\apache\repp_copy\Java\processing\lib\log4j-1.2.16.jar" />
<pathelement location="C:\apache\repp_copy\Java\processing\lib\mailapi.jar" />
</path>
<target name="compile" depends="clean">
<javac srcdir="src" destdir="Build/tnxBuild" debug="true" encoding="utf-8">
<classpath refid="project.class.path" />
</javac>
<copy todir="Build/tnxBuild">
<fileset dir="src">
<include name="*.properties"/>
</fileset>
</copy>
</target>
<target name="compileMcVpc" depends="clean, compile">
<javac srcdir="module-thx/src" destdir="Build/tnxBuild" debug="true" encoding="utf-8">
<classpath refid="project.class.path" />
</javac>
<copy todir="Build/tnxBuild">
<fileset dir="module-thx/src">
<include name="*.properties"/>
</fileset>
</copy>
</target>
<fileset id="common" dir="lib">
<include name="*.jar" />
</fileset>
<target name="createJar" depends="compileMcVpc,clean,compile">
<war destfile="thx.jar" webxml="module-thx/web/WEB-INF/web.xml">
<lib refid="common" />
<classes dir="${project.location}/Build/tnxBuild">
</classes>
<metainf file="module-thx/web/META-INF/context.xml">
</metainf>
<fileset id="content" dir="${project.location}/module-thx/web">
<include name="*/*.*" />
<include name="*.*" />
</fileset>
<!--<metainf file="front_web/web/META-INF/context.xml">
</metainf>-->
<!--<fileset id="content" dir=".">
<include name="*.*" />
</fileset>-->
</war>
</target>
<target name="clean">
<delete dir="Build/tnxBuild" />
<mkdir dir="Build/tnxBuild" />
</target>
<target name="runApp" depends="createJar">
<delete dir="${webapps.location}/thx.jar" />
<copyfile src="thx.jar" dest="C:\apache\repp_copy\Java\processing\jars\thx.jar" />
<delete dir="thx.jar" />
</target>
</project>
PS所有目录都是正确的,仔细检查。控制台的结果:
Buildfile: C:\apache\repp_copy\Java\processing\build-Tnx.xml
BUILD SUCCESSFUL
Total time: 422 milliseconds