日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Ant编译、FatJar编译方式

發布時間:2025/3/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Ant编译、FatJar编译方式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

FatJar方式:

在Eclipse下生成jar包分很多種情況。最簡單的情況是沒有用到第三方jar包,那么直接Export就可以生成jar包。但是如果用到了第三方jar包,那么就比較繁瑣了,很不方便。FatJar可以解決這個問題,使用FatJar,即使包含了很多第三方jar包,也可以很方便的生成jar包。

安裝方法:

1. eclipse在線更新方法:help > Install New Sofware > Add...

name:FatJar

URL:http://kurucz-grafika.de/fatjar

2. eclipse插件安裝方法:

鏈接:https://pan.baidu.com/s/1eS2HZpw 密碼:0dz5

解壓后,將解壓出的plugins中的文件復制到eclipse中的plugins目錄下

然后重啟eclipse,避免Fat Jar被認不出來,在eclipse啟動時使用-clean參數

參考文檔:http://blog.csdn.net/ithomer/article/details/16805269

?

Ant編譯方式:

環境搭建:鏈接:https://pan.baidu.com/s/1gf0EhO3 密碼:w6h3

jdk和ant下載:鏈接:https://pan.baidu.com/s/1sln2AiL 密碼:mdku

使用Ant打包是比較方便的,我們可以在項目根目錄下建立一個名為build.xml的xml文件,然后在xml文件里面定義我們的打包任務,如下:

打jar 包時文件內容:

<project default="jar" name="edi_salary_pfm"> <property name="lib.dir" value="lib"/> <property name="src.dir" value="src"/> <property name="resource.dir" value="${src.dir}/resources"/><property name="output.dir" value="build"/> <property name="classes.dir" value="${output.dir}/classes"/> <property name="jarname" value="edi_salary_pfm"/> <!-- 第三方jar包的路徑 --> <path id="lib-classpath"> <fileset dir="${lib.dir}"> <include name="**/*.jar"/> </fileset> </path> <path id="base.path"><!-- 需要在window->preferences->ant->runtime->properties 加上common_lib變量,指向hrms_common_lib的根目錄 --><fileset dir="D:\source\truck\common_lib"><include name="*.jar" /></fileset></path><!-- 1. 初始化工作,如創建目錄等 --> <target name="init"> <mkdir dir="${classes.dir}"/> <mkdir dir="${output.dir}"/> </target> <!-- 2. 編譯 --> <target name="compile" depends="init"> <javac srcdir="${src.dir}" destdir="${classes.dir}"> <compilerarg line="-encoding UTF-8"/> <classpath refid="lib-classpath"/> <classpath refid="base.path"/> </javac><copy todir="${classes.dir}"><fileset dir="${resource.dir}"></fileset></copy></target> <!-- 3. 打包jar文件 --> <target name="jar" depends="compile"> <copy todir="${output.dir}/lib"> <fileset dir="${lib.dir}"/> </copy> <!--Create a property containing all .jar files, prefix lib/, and seperated with a space--> <pathconvert property="mf.classpath" pathsep=" "> <mapper> <chainedmapper> <!-- jar包文件只留文件名,去掉目錄信息 --> <flattenmapper/> <!-- add lib/ prefix --> <globmapper from="*" to="lib/*"/> </chainedmapper> </mapper> <path refid="lib-classpath"/> <path refid="base.path"/> </pathconvert> <!-- jar文件的輸出路徑 需要比對一下先前的打包buid.xml文件看看要過濾掉那些文件 --><jar jarfile="${output.dir}/${jarname}.jar"><fileset dir="${classes.dir}"><!--<exclude name="**/config/**"/><exclude name="**/spring/dataAccessContext.xml"/><exclude name="ibatis/sql-map-config.xml"/><exclude name="spy.properties"/>--></fileset></jar></target> </project>

?

打war包文件內容:

<project name="empleave" default="war-with-compiledjsp-weblogic"> <!--default 默認執行的任務,此處任務包含tomcat和weblogic的任務,因此可針對項目運行環境選擇打包相應的war包 --><description>empleave.application</description><property name="project.name" value="empleave" /><property name="project.version" value="1.0" /><property name="project.encoding" value="UTF-8" /><property name="dir.src.java" value="${basedir}/src/java" /><property name="dir.src.resource" value="${basedir}/src/resources" /><property name="dir.src.test" value="${basedir}/src/test" /><property name="dir.src.web" value="${basedir}/WebRoot" /><property name="dir.src.lib" value="${basedir}" /><property name="dir.build" value="build" /><property name="dir.build.doc" value="${dir.build}/docs" /><property name="dir.build.doc.api" value="${dir.build.doc}/api" /><property name="dir.build.classes" value="${dir.build}/classes" /><property name="dir.build.test-classes" value="${dir.build}/test-classes" /><property name="dir.build.testreport" value="${dir.build}/test-reports" /><property name="dir.build.jspc" value="${dir.build}/jspc" /><property name="compile.debug" value="true" /><property name="javac.target" value="1.5" /><path id="base.path"><!-- 需要在window->preferences->ant->runtime->properties 加上common_lib變量,指向hrms_common_lib的根目錄 --><fileset dir="D:\source\branches_compile_all\common_lib"><include name="*.jar" /></fileset></path><!-- project class path --><path id="classpath"><path refid="base.path" /><fileset dir="${dir.src.lib}"><include name="*.jar" /></fileset><fileset dir="${dir.src.web}/WEB-INF/lib"><include name="*.jar" /></fileset></path><!--tomcat jsp compile class path --><path id="tomcatjspcclasspath"><fileset dir="${tomcat.jspc.lib}"><include name="*.jar" /></fileset><path refid="base.path" /><fileset dir="${dir.src.lib}"><include name="*.jar" /></fileset><fileset dir="${dir.src.web}/WEB-INF/lib"><include name="*.jar" /></fileset></path><!--weblogic jsp compile class path <path id="weblogicjspcclasspath"><fileset dir="${weblogic.jspc.lib}"><include name="*.jar" /></fileset><path refid="base.path"/><fileset dir="${dir.src.lib}"><include name="*.jar" /></fileset> <fileset dir="${dir.src.web}/WEB-INF/lib"><include name="*.jar" /></fileset></path>--><path id="weblogicjspcclasspath"><fileset dir="D:\branches_compile_all\weblogic9.2.2.0_lib"><include name="*.jar" /></fileset><fileset dir="C:\Program Files (x86)\Java\jdk1.5.0_22\lib"><include name="*.jar" /></fileset><path refid="base.path" /><fileset dir="${dir.src.lib}"><include name="*.jar" /></fileset><fileset dir="${dir.src.web}/WEB-INF/lib"><include name="*.jar" /></fileset></path><!-- init task --><target name="init" depends="clean"><mkdir dir="${dir.build}" /><mkdir dir="${dir.build.doc}" /><mkdir dir="${dir.build.doc.api}" /><mkdir dir="${dir.build.classes}" /><mkdir dir="${dir.build.test-classes}" /><mkdir dir="${dir.build.testreport}" /><mkdir dir="${dir.build.jspc}" /></target><!-- default build task --><target name="tomcatbuild" depends="clean"><ant target="jar" /><ant target="tomcatwar" /><ant target="javadoc" /><echo message="Build completed!" /></target><!-- default build task --><target name="weblogicbuild" depends="clean"><ant target="jar" /><ant target="weblogicwar" /><ant target="javadoc" /><echo message="Build completed!" /></target><!-- tomcat jspc --><target name="tomcatjspc"><taskdef classname="org.apache.jasper.JspC" name="tomcatjasper"><classpath refid="tomcatjspcclasspath" /></taskdef><tomcatjasper javaencoding="UTF-8" trimspaces="true" uriroot="${dir.src.web}" webxmlfragment="${dir.src.web}/WEB-INF/jsp-web.xml" outputDir="${dir.build.jspc}" failonerror="false" /><loadfile property="jspc.webxml.fragment.contents" srcFile="${dir.src.web}/WEB-INF/jsp-web.xml" /><copy file="${dir.src.web}/WEB-INF/web.xml" tofile="${dir.src.web}/WEB-INF/merge-web.xml" /><replace file="${dir.src.web}/WEB-INF/merge-web.xml" encoding="UTF-8"><replacefilter token="&lt;!--@JSPC-INSERT@--&gt;" value="${jspc.webxml.fragment.contents}" /></replace></target><target name="tomcat-compile-jsp" depends="tomcatjspc"><javac destdir="${dir.src.web}/WEB-INF/classes" optimize="on" debug="${compile.debug}" failonerror="false" srcdir="${dir.build.jspc}" encoding="UTF-8" target="${javac.target}"><classpath refid="tomcatjspcclasspath" /><include name="**/*.*" /><exclude name="**/storage/query_jsp*.*" /><exclude name="loader/**/*.*" /><exclude name="*.ser" /></javac></target><!-- tomcat jspc --><!-- weblogic jspc --><target name="weblogicjspc"><java classname="weblogic.jspc" classpathref="weblogicjspcclasspath" fork="true" failonerror="false" maxmemory="512m"><arg line="-webapp ${dir.src.web} -d ${dir.src.web}/WEB-INF/classes -compileAll" /></java></target><target name="weblogic-compile-jsp" depends="weblogicjspc"><!--<javac destdir="${dir.src.web}/WEB-INF/classes" optimize="on" debug="${compile.debug}" failonerror="false" srcdir="${dir.build.jspc}" encoding="UTF-8" target="${javac.target}"><classpath refid="weblogicjspcclasspath" /><include name="**/*.*" /><exclude name="**/storage/query_jsp*.*" /><exclude name="loader/**/*.*" /><exclude name="*.ser" /></javac>--></target><!-- weblogic jspc --><target name="deploy-web" depends="compile"><mkdir dir="${dir.src.web}/WEB-INF/classes" /><copy todir="${dir.src.web}/WEB-INF/classes"><fileset dir="${dir.build.classes}"></fileset></copy></target><!-- archive the web app folder with war--><target name="war" depends="deploy-web"><war destfile="${dir.build}/${project.name}.war" webxml="${dir.src.web}/WEB-INF/web.xml"><fileset dir="${dir.src.web}"><include name="**/*.*" /><exclude name="**/build.xml" /><exclude name="**/build.properties" /><exclude name="**/deploy.xml" /><exclude name="**/resin-web.xml" /><exclude name="**/targets.xml" /><exclude name="**/undeploy.xml" /><!--<exclude name="**/weblogic.xml"/>--><exclude name="**/jsp-web.xml" /><exclude name="**/merge-web.xml" /><exclude name="**/portal-filter.config" /><exclude name="**/portal-listener.config" /><exclude name="html/mytest/" /><exclude name="html/sample/" /><exclude name="html/test/" /></fileset></war></target><!-- archive the web app folder with war tomcat--><target name="war-with-compiledjsp-tomcat" depends="deploy-web,tomcat-compile-jsp"><war destfile="${dir.build}/${project.name}.war" webxml="${dir.src.web}/WEB-INF/web.xml"><fileset dir="${dir.src.web}"><include name="**/*.*" /><exclude name="**/build.xml" /><exclude name="**/build.properties" /><exclude name="**/deploy.xml" /><exclude name="**/resin-web.xml" /><exclude name="**/targets.xml" /><exclude name="**/undeploy.xml" /><!--<exclude name="**/weblogic.xml"/><exclude name="**/jsp-web.xml" /><exclude name="**/merge-web.xml" />--></fileset></war></target><!-- archive the web app folder with war weblogic--><target name="war-with-compiledjsp-weblogic" depends="deploy-web,weblogic-compile-jsp"><war destfile="${dir.build}/${project.name}.war" webxml="${dir.src.web}/WEB-INF/web.xml"><fileset dir="${dir.src.web}"><include name="**/*.*" /><exclude name="**/build.xml" /><exclude name="**/build.properties" /><exclude name="**/deploy.xml" /><exclude name="**/resin-web.xml" /><exclude name="**/targets.xml" /><exclude name="**/undeploy.xml" /><!--<exclude name="**/weblogic.xml"/><exclude name="**/jsp-web.xml" /><exclude name="**/merge-web.xml" />--></fileset></war></target><!-- clean all the builded resources --><target name="clean" depends="clean-web"><delete dir="${dir.build}" excludes=".svn" includeemptydirs="true" /></target><!-- clean all the builded resources --><target name="clean-web"><delete dir="${dir.src.web}/WEB-INF/classes" excludes=".svn" includeemptydirs="true" /></target><!-- compile java source only --><target name="compile" depends="init"><javac destdir="${dir.build.classes}" encoding="${project.encoding}" nowarn="true" debug="${compile.debug}" target="${javac.target}"><src><pathelement location="${dir.src.java}" /></src><classpath refid="classpath" /></javac><copy todir="${dir.build.classes}"><fileset dir="${dir.src.java}"><exclude name="**/*.java" /><include name="**/*.*" /></fileset><fileset dir="${dir.src.resource}"><exclude name="**/*.java" /><include name="**/*.*" /></fileset></copy></target><!-- jar task,jar the compiled java classes,does not include the test classes. --><target name="jar" depends="compile" description="Create the jar"><jar jarfile="${dir.build}/${project.name}-${project.version}.jar"><fileset dir="${dir.build.classes}"><include name="**/*" /></fileset></jar><copy file="${dir.build}/${project.name}-${project.version}.jar" tofile="${dir.build}/${project.name}.jar" /></target><!-- javadoc task,generate java source code api doc,does not include the test source--><target name="javadoc"><javadoc Encoding="${project.encoding}" sourcepath="${dir.src.java}" destdir="${dir.build.doc.api}" author="true" version="true" use="true" packagenames="net.bingosoft.*" Windowtitle="api documentation"><classpath refid="classpath" /></javadoc></target> </project>

?

轉載于:https://my.oschina.net/yabushan/blog/1596830

總結

以上是生活随笔為你收集整理的Ant编译、FatJar编译方式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。