使用maven打包jar或者war
如何把配置文件打包到jar中 http://blog.csdn.net/ciedecem/article/details/10382275
maven打包总结 http://blog.csdn.net/fireofjava/article/details/14447325
maven打jar包 http://hy90171.iteye.com/blog/1916293
使用maven打出独立应用程序的jar包 http://pipilu.iteye.com/blog/399816
maven生成war包的两种方式http://touchfu.iteye.com/blog/545708
Maven 是怎样创建War 包? http://my.oschina.net/u/939534/blog/173863
打包参数:
mvn package -P saas -Dwar.name=dfxd -Ddb.name=dfxd
注意:D参数可以使用多次,匹配pom.xml里面定义的属性。
1. 打包jar时,想排除所有的resource文件
maven 生成的jar文件指定main class http://qinglangee.iteye.com/blog/709961
-
12345678910111213141516171819202122232425262728293031323334353637383940Xml代码<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>zhch.illq.time</groupId><artifactId>time_tool</artifactId><packaging>jar</packaging><version>1.0-SNAPSHOT</version><name>time_tool</name><url>http://maven.apache.org</url><!-- 指定属性 --><properties><cxf.version>2.2.8</cxf.version><spring.version>3.0.2.RELEASE</spring.version></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><archive><manifest><mainClass>zhch.illq.time.TimeTool</mainClass></manifest></archive></configuration></plugin></plugins></build></project>
jar 命令:
假设现在是在classes目录的同级目录中
jar cvef zhch.illq.time.TimeTool timetool.jar -C classes .
-C 是指定要打包的目录
. (点) 是文件,表示当前目录,这样就把classes目录中及子目录中所有文件打包
参数e f 分别指定main class和生成的jar文件名, 后面要按顺序来
也可以写成这样
jar cvfe timetool.jar zhch.illq.time.TimeTool -C classes .
maven 将代码打成可执行jar包 http://my.oschina.net/u/147181/blog/164938
在Eclipse中编写代码,如果没有用到第三方jar可以直接export成jar包,但是如果用到第三方jar包,就需要手动将拷贝依赖的jar包,也可以编写ant脚本自动打包。更方便的是使用maven,现在maven管理项目很方便,如下面将自己编写的类打成可执行jar包,并自动拷贝依赖的jar包。 下面是pom.xml文件:
执行 maven install就会在项目target文件夹下生成jar包,和依赖的jar包(在lib文件夹中),直接运行 java -jar *.jar即可。
2. 打war包时排除resource
打包时过滤和包含文件例子
注意:pom.xml定义的一些属性,是可以被使用到applicationContext.xml里面的,
比如:pom.xml存在<hibernate.dialect>org.hibernate.dialect.SQLServerDialect</hibernate.dialect>,然后jdbc.properties存在hibernate.dialect=${hibernate.dialect},applicationContext.xml存在<prop key=”hibernate.dialect”>${hibernate.dialect}</prop>,那么打包得到的war,applicationContext.xml会变为:<prop key=”hibernate.dialect”>org.hibernate.dialect.SQLServerDialect</prop>