Java打包是算是个事吧。打个war包或者jar包在所难免。一般情况下有使用jdk带的命令直接打和使用ant的两种方式。今天就把这两种方式整理下吧。
1.1 打war包
1.1使用命令
>jar cvf project_name.war //展开jar xvf project_name.war
1.2 ant
View Code
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project basedir="." default="buildwar" name="PMS-Depoly">
3 <property name="build.number" value="1.0.0" />
4
5 <!-- 应用名称-->
6 <property name="appname" value="spl" />
7
8 <!--目标目录 , 如deploy-->
9 <property name="deploy.dir" value="deploy" />
10
11 <!-- ============================================= -->
12 <!-- build .war file -->
13 <!-- ============================================= -->
14 <target name="buildwar" depends="">
15 <war destfile="${deploy.dir}/${appname}-${build.number}.war" webxml="WebRoot/WEB-INF/web.xml" defaultexcludes="true" >
16 <fileset dir="WebRoot">
17 <exclude name="**/*.log" />
18 <exclude name="**/work/**" />
19 <exclude name="**/tmp/**" />
20 </fileset>
21 </war>
22 </target>
23
24 </project>
2 <project basedir="." default="buildwar" name="PMS-Depoly">
3 <property name="build.number" value="1.0.0" />
4
5 <!-- 应用名称-->
6 <property name="appname" value="spl" />
7
8 <!--目标目录 , 如deploy-->
9 <property name="deploy.dir" value="deploy" />
10
11 <!-- ============================================= -->
12 <!-- build .war file -->
13 <!-- ============================================= -->
14 <target name="buildwar" depends="">
15 <war destfile="${deploy.dir}/${appname}-${build.number}.war" webxml="WebRoot/WEB-INF/web.xml" defaultexcludes="true" >
16 <fileset dir="WebRoot">
17 <exclude name="**/*.log" />
18 <exclude name="**/work/**" />
19 <exclude name="**/tmp/**" />
20 </fileset>
21 </war>
22 </target>
23
24 </project>
2 jar包
2.1 命令
>jar cf .\lib\name.jar src_dir
使用 m 选项,把指定文件名的manifest文件 传入,例如
jar cvfm name.jar myapplication.mf src_dir
2.2 ant
View Code
1 <target name="buildjar" depends="">
2 <delete file="${component.classes.dir}/${appname}-${build.number}.jar" />
3 <javac destdir="${component.classes.dir}" srcdir="${src.dir}" debug="${debug}">
4 <include name="**" />
5 </javac>
6 <!-- Building EJB JAR -->
7 <jar destfile="${component.classes.dir}/${appname}-${build.number}.jar">
8 <!-- classes, deployment descriptors etc -->
9 <fileset dir="${component.classes.dir}" />
10 <manifest>
11 <attribute name="Main-Class" value="com.ant.djj.test.MyAnt" />
12 </manifest>
13 </jar>
14 <!-- End of building JAR -->
15
16 <delete includeemptydirs="true">
17 <fileset dir="${component.classes.dir}" includes="**/*" excludes="${appname}-${build.number}.jar" />
18 </delete>
19
20 </target>
2 <delete file="${component.classes.dir}/${appname}-${build.number}.jar" />
3 <javac destdir="${component.classes.dir}" srcdir="${src.dir}" debug="${debug}">
4 <include name="**" />
5 </javac>
6 <!-- Building EJB JAR -->
7 <jar destfile="${component.classes.dir}/${appname}-${build.number}.jar">
8 <!-- classes, deployment descriptors etc -->
9 <fileset dir="${component.classes.dir}" />
10 <manifest>
11 <attribute name="Main-Class" value="com.ant.djj.test.MyAnt" />
12 </manifest>
13 </jar>
14 <!-- End of building JAR -->
15
16 <delete includeemptydirs="true">
17 <fileset dir="${component.classes.dir}" includes="**/*" excludes="${appname}-${build.number}.jar" />
18 </delete>
19
20 </target>
如果打入mf文件 可以加入这
<target name="jar">
<jar jarfile ="myapplication.jar"
manifest="myapplication.mf">
<fileset dir="classdir"
includes="**/*.class"/>
</jar>
</target>
本文来自博客园,作者:茄子_2008,转载请注明原文链接:https://www.cnblogs.com/xd502djj/archive/2011/02/14/1954460.html