IDEA ant 生成javaWeb项目的jar包build.xml文件模板

IDEA ant 生成javaWeb项目的jar包build.xml文件参考模板;
build.xml文件内容如下:

<?xml version="1.0"?> 
<!-- 定义一个工程,默认任务为warFile -->
<project default="antwar" name="helloWord" basedir="."> 
 <!-- 定义属性,打成war包的名称。 -->
	<description>Java project</description>   
	<property name="helloWordJar" value="helloWord.jar"/>
	<property name="helloWordWar" value="helloWord.war"/>
	<property name="libDir" value="${basedir}/webapps/WEB-INF/lib" />
	<property name="webapp_path" value="${basedir}/Webapps"></property>
	
<!-- 定义路径,编译java文件时用到的jar包。 -->
	<path id="project.lib">
		<fileset dir="${libDir}">
			<include name="**/*.jar"/>
		</fileset>
	</path>
    <!-- 定义任务,清空任务:清空原有的class文件,创建新的build路径。 -->
    <target name="clean">
    	<delete verbose="true" includeemptydirs="true"> 
    	            <fileset dir="${webapp_path}/WEB-INF/classes/com"> 
    	                <include name="**/*.class"/> 
    	            </fileset> 
    	</delete>
    </target>
	   <!-- 定义任务,编译src文件夹中的java文件,编译后的class文件放到创建的文件夹下。 -->
	<target name="complie" depends="clean">
		<javac srcdir="${basedir}/src" destdir="${webapp_path}/WEB-INF/classes" encoding="UTF-8">
			       <compilerarg value="-XDignore.symbol.file"/>
					<classpath refid="project.lib">	
					</classpath>	
		</javac>
	</target>
	
	 <!-- 将Class文件集合成jar包。 -->
    <target name="antjar" depends="complie">
    	<!--<delete file="${libDir}/${helloWordJar}"/>-->
  		<jar destfile="${libDir}/${helloWordJar}" basedir="${webapp_path}/WEB-INF/classes" includes="**/*.class"/>   
    </target>	
				
	<!-- 将CALSS文件合成的JAR及其他文件集合成war包。 -->
	<target name="antwar" depends="antjar" description="打war包">
	  <!-- 删除原有war包。 -->
        <delete dir="${basedir}/${helloWordWar}" />
        <!-- 建立新war包。 -->
        <war destfile="${basedir}/${helloWordWar}" webxml="${webapp_path}/WEB-INF/web.xml">
            <!-- 将非jar和非class文件拷贝到war包的对应路径下。 -->
            <fileset dir="${webapp_path}">
                <include name="**/**.*" />
                <exclude name="**/*.jar"/>
                <exclude name="**/*.class"/>
            </fileset>
            <!-- 将jar和class文件拷贝到war包的对应路径下。 -->
            <lib dir="${webapp_path}/WEB-INF/lib" />        	
        </war>	
	</target>	
</project>

猜你喜欢

转载自blog.csdn.net/liangbao568/article/details/125452785