Use ANT and Maven to create executable jar with dependent library
来源:互联网 发布:安易数据恢复软件免费 编辑:程序博客网 时间:2024/06/07 00:56
As we all know, we can use java jar command and IDE (Eclipse, Net-Bean and etc) export tools to generate the java jar file. Sometime, it is more convenient and maintainable to use ANT and Maven to do this task.
ANT demo:
<?xml version="1.0" encoding="UTF-8"?><project name="MyProject" default="jar"> <!-- Name of the output .jar file --> <property name="jar.name" value="jar_name.jar" /> <!-- Base directory for distribution target --> <property name="deploy.home" value="." /> <!-- Base directory for compilation targets --> <property name="build.home" value="." /> <!-- Main class --> <property name="main.class" value="my.path.to.the.main.Application" /> <!-- The base directory for all libraries (jar) files --> <property name="lib.home" value="lib" /> <target name="jar" description="Create jar and MANIFEST.MF"> <pathconvert property="libs.project" pathsep=" "> <mapper> <chainedmapper> <!-- remove absolute path --> <flattenmapper /> <!-- add lib/ prefix --> <globmapper from="*" to="lib/*" /> </chainedmapper> </mapper> <path> <!-- lib.home contains all jar files, in several subdirectories --> <fileset dir="${lib.home}"> <include name="**/*.jar" /> </fileset> </path> </pathconvert> <!-- create the jar --> <jar jarfile="${deploy.home}/${jar.name}" basedir="${build.home}/classes"> <manifest> <attribute name="Built-By" value="${user.name}" /> <attribute name="Main-Class" value="${main.class}" /> <!-- Finally, use the generated libs path --> <attribute name="Class-Path" value="${libs.project}" /> </manifest> </jar> </target></project>Maven sample
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.wonder.core</groupId><artifactId>superman</artifactId><packaging>jar</packaging><version>1.0</version><name>superman</name><url>http://maven.apache.org</url> <properties><jdk.version>1.6</jdk.version><log4j.version>1.2.17</log4j.version></properties> <dependencies> <dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>${log4j.version}</version></dependency> </dependencies> <build><plugins> <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>${jdk.version}</source><target>${jdk.version}</target></configuration> </plugin> <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>2.4</version><configuration><archive> <manifest><addClasspath>true</addClasspath><mainClass>com.wonder.core.App</mainClass><classpathPrefix>dependency-jars/</classpathPrefix> </manifest></archive></configuration> </plugin> <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>2.5.1</version><executions> <execution><id>copy-dependencies</id><phase>package</phase><goals><goal>copy-dependencies</goal></goals><configuration><includeGroupIds>log4j</includeGroupIds><outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory></configuration> </execution> </executions></plugin> </plugins></build> </project>
- Use ANT and Maven to create executable jar with dependent library
- How to create a DLL library in C and then use it with C#
- How to: Create and Use a Data Connection Library
- How to create a jar file with Maven
- create and use win32 static library
- How to Create and Use the DLL
- spring+maven项目报错:Unable to create JDK 1.5 dependent parser
- Create a Bundle Jar With Ant:使用Ant创建一个包含所有依赖的JAR包
- How to create aligned partitions in Linux for use with NetApp LUNs, VMDKs, VHDs and other virtual di
- how to use Dom to create and remove element
- How to use maven to export a runnable jar
- How to Create, Use and Maintain DataStage 8 Parameter Sets
- Use ZFS and CIFS to create a home NAS box
- Use the JQuery To upload images and create thumbnail
- how-to-create-and-use-your-own-icon-fonts
- How to register and use the native Kentico jQuery library
- Sodium: A Modern and Easy-to-Use Crypto Library
- How to use Ant
- 项目管理心得:一个项目经理的个人体会、经验总结 .
- sql date类型转换以及date格式的转换
- serial number status
- flex ibatis java 通过sql语句进行多条件模糊查询。
- Android Lint简介
- Use ANT and Maven to create executable jar with dependent library
- ServletContext
- Oracle11g的安装和基本使用
- mysql删除地址栏所指定的id
- HTML(XML)转义字符大全
- 走马观花 --- 网络身份认证协议Kerberos (一)
- BBS项目笔记之三:前台带分类的搜索框
- Gallery和GridView 小结
- 小车的移动的测试程序