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编译方式相关推荐

  1. 企业应用的Ant模组编译环境

    摘要: 编译环境对于今日的Java企业级应用程序来说,越来越难于管理了.堆积如山的代码,配置文件,以及对第三方的依赖(third-party dependencies)都使得管理编译环境变得困难.本文 ...

  2. Nacos 快速开始、版本选择、预备环境准备、下载源码或者安装包、从 Github 上下载源码方式、下载编译后压缩包方式、配置nacos、配置集群、启动服务器、服务注册发现和配置管理、关闭服务器

    1.Nacos 快速开始 1.1.版本选择 1.2.预备环境准备 1.3.下载源码或者安装包 1.3.1.从 Github 上下载源码方式 1.3.2.下载编译后压缩包方式 1.3.3.配置nacos ...

  3. java aot,Java三种编译方式: 前端编译 JIT编译 AOT编译

    java程序代码需要编译后才能在虚拟机中运行,编译涉及到非常多的知识层面:编译原理.语言规范.虚拟机规范.本地机器码优化等:了解编译过程有利于了解整个Java运行机制,不仅可以使得我们编写出更优秀的代 ...

  4. c mysql 编译_MySQL编译安装之cmake

    mysql版本5.5以上编译安装时需要用到软件cmake,cmake特性是独立于源码编译,编译工作可以在另外一个目录中而非源码目录中进行, mysql版本5.5以上编译安装时需要用到软件cmake,c ...

  5. python编译反编译,你不知道的心机与陷阱

    谈到python的文件后缀,说眼花缭乱也不为过.来看看你遇到过哪些类型! .py 如果这个不知道,呵呵-那请出门左拐,你还是充钱那个少年,没有一丝丝改变.接着打游戏去吧- .pyc 这个后缀应该算是除 ...

  6. 了解“预编译、编译、汇编、链接”这四个过程对你有很大帮

    转自:胡薇 了解"预编译.编译.汇编.链接"这四个过程对你有很大帮助-电子发烧友网 如有侵权,告知立马删除 补充:C语言条件编译及编译预处理阶段 - Rusty's code - ...

  7. UE4编译grpc,编译打包

    UE4编译grpc,编译打包 一.源码下载与编译 下载UE4.27.2源码 需要先注册UE的账号: https://www.unrealengine.com/zh-CN/ 需要有github.com账 ...

  8. Android编译及编译脚本、Android构建基础学习笔记

    Android编译及编译脚本.Android构建基础学习笔记 Android编译及编译脚本 概述 Android.mk转换成Android.bp 例子(简单Android.mk文件转Android.b ...

  9. 反编译与反汇编、C++编译过程,包括预编译--汇编--编译--链接

    参考:C/C++程序编译流程(预处理->编译->汇编->链接) - ProLyn - 博客园 反汇编和反编译的区别_代码小卒_新浪博客 反汇编与反编译: 汇编:是把汇编源程序转变为目 ...

  10. php windows 编译,Windows编译PHP7.2拓展

    准备工作https://github.com/Microsoft/php-sdk-binary-tools下载PHP-SDK(在右边的"clone or download"点击,选 ...

最新文章

  1. 极视教育的课程怎么样_蒲公英教育加盟怎么样?
  2. 服务器搭建邮件自动回复,在postfix邮件系统上搭建自动回复邮件系统
  3. python turtle画彩虹-python绘制樱花,彩虹旋等
  4. 一个晚上,输掉了整个世界!
  5. [LeetCode] Restore IP Addresses 复原IP地址
  6. tomcat基本使用和超图基本jsp例子
  7. 谈谈程序员的高薪现象是不是该整治一下了?
  8. 理解TCP的通信原理及IO阻塞
  9. 具有GlassFish和一致性的高性能JPA –第1部分
  10. arduino joy_如何用Joy开发Kubernetes应用
  11. 2021年度最佳开源软件榜单出炉!
  12. 关于“指针数组”和”数组指针“
  13. VS2012下基于Glut OpenGL glEdgeFlag示例程序:
  14. [开发回忆录]第三方模块的松耦合
  15. 更好的为学计算机帮助英语,北京教委公布本科跨省转学名单,两学霸为学计算机转出北大...
  16. 中国身份证号码验证,支持15,18位
  17. curl 504 php,nginx - PHP 经常提示 504 Gateway Time-out
  18. 【PS】如何简单的处理带晒伤皮肤的婚纱照?红斑/脱皮/减淡红色
  19. win7语言设置为英语
  20. Shader Forge 入门学习(二) 实现发光、火焰燃烧、溶解、扭曲效果

热门文章

  1. 忘记农民就是忘本-农业大健康·万祥军:不要说自己是教授
  2. liteIDE配置环境变量
  3. File Transfer(并查集)
  4. windows安装两个版本JDK
  5. windbg调试实例(4)--句柄泄露
  6. 一个略复杂的数据映射聚合例子及代码重构
  7. 20170512 Python练习册0004统计英文的纯文本文件的单词出现的个数
  8. MSSQL - 通用存储过程
  9. 怎样 获取 ios的系统版本
  10. 节点操作-创建并添加删除节点替换克隆节点