编程小贴士

给你的编程提供小点子


maven关于打包的那些插件

在工作中使用maven创建java工程,管理jar包依赖,方便快捷。根据需要,需要把工程打包成各种需要的形式,这些打包插件就用到了。
现将各种打包用到的插件总结到这里,你可以参考官方文档,修改或者增加适合你的参数。

第一个:打源码包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<plugin>  
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-source-plugin</artifactId>  
	<version>2.1</version>  
	<configuration>  
		<attach>true</attach>  
	</configuration>  
	<executions>  
		<execution>  
			<phase>compile</phase>  
			<goals>  
				<goal>jar</goal>  
			</goals>  
		</execution>  
	</executions>  
</plugin>

第二个:打全量包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-shade-plugin</artifactId>
	<version>1.2.1</version>
	<executions>
		<execution>
			<phase>package</phase>
			<goals>
				<goal>shade</goal>
			</goals>
			<configuration>
				<transformers>
					<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
						<mainClass>com.zhaoyanblog.Launcher</mainClass>
					</transformer>
					<!--防止spring多个包同名配置文件覆盖-->
					<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
						<resource>META-INF/spring.handlers</resource>
					</transformer>
					<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
					   <resource>META-INF/spring.schemas</resource>
					</transformer
				</transformers>
			</configuration>
		</execution>
	</executions>
</plugin>

第三个:copy依赖jar包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-dependency-plugin</artifactId>
	<executions>
		<execution>
			<id>copy</id>
			<phase>package</phase>
			<goals>
				<goal>copy-dependencies</goal>
			</goals>
			<configuration>
				<includeScope>runtime</includeScope>
				<outputDirectory>target/lib/</outputDirectory>
			</configuration>
		</execution>
	</executions>
</plugin>

第四个:指定main方法,修改manifest文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<version>2.3.2</version>
	<configuration>
		<archive>
			<manifest>
				<addClasspath>true</addClasspath>
				<classpathPrefix>lib</classpathPrefix>
				<mainClass>com.zhaoyanblog.Launcher</mainClass>
			</manifest>
			<manifestEntries>
				<Class-Path>conf/</Class-Path>
			</manifestEntries>
		</archive>
		<finalName>tools-${project.version}</finalName>
	</configuration>
</plugin>

第五个:打压缩包。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-assembly-plugin</artifactId>
	<version>2.4</version>
	<executions>
		<execution>
			<id>make-tar.gz</id>
			<phase>package</phase>
			<goals>
				<goal>single</goal>
			</goals>
			<configuration>
				<finalName>${project.build.finalName}</finalName>
				<skipAssembly>false</skipAssembly>
				<descriptors>
					<descriptor>tar.gz.xml</descriptor>
				</descriptors>
			</configuration>
		</execution>
	</executions>
</plugin>

同时要增加一个tar.gz.xml文件,描述打包内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?xml version="1.0" encoding="UTF-8"?>
 
<assembly 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/xsd/assembly-1.0.0.xsd">
	<id>package</id>
	<formats>
		<format>tar.gz</format>
	</formats>
	<includeBaseDirectory>false</includeBaseDirectory>
	<fileSets>
		<fileSet>
			<directory>bin</directory>
			<outputDirectory>/</outputDirectory>
			<fileMode>0755</fileMode>
			<directoryMode>0755</directoryMode>
		</fileSet>
		<fileSet>
			<directory>${project.build.directory}/conf</directory>
			<outputDirectory>/conf</outputDirectory>
			<includes>
				<include>*.xml</include>
				<include>*.properties</include>
			</includes>
		</fileSet>
	</fileSets>
	<files>
		<file>
			<source>${project.build.directory}/${project.build.finalName}.jar</source>
			<destName>/${project.build.finalName}.jar</destName>
		</file>
	</files>
	<dependencySets>
		<dependencySet>
			<outputDirectory>lib</outputDirectory>
			<scope>runtime</scope>
		</dependencySet>
	</dependencySets>
</assembly>

转自:赵岩的博客
地址:http://zhaoyanblog.com/archives/674.html

124 Responses to “ maven关于打包的那些插件 ”

  1. mia pron khalifa说道:

    CbyR68 I?аАТ’аЂа†ll right away seize your rss feed as I can at in finding your email subscription link or newsletter service. Do you have any? Please let me realize in order that I may just subscribe. Thanks.

  2. best pron说道:

    6QQJxl Wow, great article post.Really looking forward to read more.

  3. This is my first time visit at here and i am truly happy to read all at one place.

  4. tra gung说道:

    Of course, what a fantastic blog and illuminating posts, I definitely will bookmark your site.Best Regards!

  5. painting说道:

    pretty practical stuff, overall I consider this is really worth a bookmark, thanks

  6. Wow! Thank you! I constantly needed to write on my website something like that. Can I take a part of your post to my website?

  7. w88 world说道:

    I truly appreciate this article post. Will read on

  8. loans will be the method where you will get your cash.

  9. woking cab说道:

    I see something truly special in this site.

  10. Please visit my website too and let me know what

  11. wander. Final tug in the class was St. Lately it has been immaculately assembled

  12. find more here说道:

    In searching for sites related to web hosting and specifically comparison hosting linux plan web, your site came up.

  13. The Lost Ways说道:

    Modular Kitchens have changed the idea of kitchen in today as world since it has provided household ladies with a comfortable yet an elegant area where they could devote their quality time and space.

  14. Citizenship说道:

    Very good article post.Really thank you! Want more.

  15. Nwokolo说道:

    Thanks so much for the blog post.Really thank you! Cool.

  16. to click. You might add a video or a pic or two to get

  17. klm coupon code说道:

    I’а†ve recently started a web site, the information you provide on this web site has helped me greatly. Thanks for all of your time & work.

  18. There is perceptibly a bunch to identify about this. I suppose you made some good points in features also.

  19. I thought it was going to be some boring old post, but it really compensated for my time. I will publish a link to this page on my blog site. I am confident my visitors will locate that really useful

  20. recycling说道:

    When I look at your website in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping.

  21. Eminem说道:

    Outstanding post, I conceive website owners should larn a lot from this website its rattling user genial.

  22. tell popeyes说道:

    This awesome blog is definitely interesting and also amusing. I have picked up a bunch of helpful stuff out of this blog. I ad love to come back again soon. Thanks a bunch!

  23. Your style is very unique in comparison to other people I ave read stuff from. Many thanks for posting when you ave got the opportunity, Guess I will just book mark this page.

  24. thietkeweb5s.top说道:

    Thanks-a-mundo for the blog post.Much thanks again.

  25. Whoa. That was a fantastic short article. Please keep writing for the reason that I like your style.

  26. David说道:

    You ave done a formidable task and our whole group shall be grateful to you.

  27. mmbanifo说道:

    respective fascinating content. Make sure you update this

  28. Lancel soldes ??????30????????????????5??????????????? | ????????

  29. I was just wondering what computer software you would need to make business cards or labels from a home computer. Is is easy or even worth the time or money..

  30. Hosting说道:

    I went over this website and I believe you have a lot of good info, saved to fav (:.

  31. Damon Moore说道:

    Very good info. Lucky me I came across your site by chance (stumbleupon). I ave book-marked it for later!

  32. Como tejer说道:

    Red your site publish and beloved it. Have you at any time thought about visitor putting up on other associated weblogs comparable to your weblog?

  33. Tejido de punto说道:

    pretty practical material, overall I think this is worthy of a bookmark, thanks

  34. Very good information. Lucky me I found your site by accident (stumbleupon). I have bookmarked it for later!

  35. Seriously, such a important online site.|

  36. stop bullying说道:

    This write-up contains fantastic original thinking. The informational content material here proves that issues arenaаАа’б‚Т€ТšаЂаŒаАа’б‚Т€ТžаБТžt so black and white. I feel smarter from just reading this.

  37. There is perceptibly a lot to identify about this. I consider you made some good points in features also.

  38. pretty beneficial material, overall I feel this is really worth a bookmark, thanks

  39. This blog was how do I say it? Relevant!! Finally I ave found something that helped me. Thank you!

  40. I truly appreciate this post. I have been looking all over for this! Thank goodness I found it on Bing. You ave made my day! Thx again

  41. darey说道:

    Preliminary writing and submitting is beneficial.

  42. This article will help the internet viewers for creating new blog or even a weblog from start to end.|

  43. I think this iis amoing thee most importnt info for me.

  44. very good submit, i definitely love this web site, carry on it

  45. We all talk a little about what you should talk about when is shows correspondence to because Maybe this has more than one meaning.

  46. There is noticeably a bunch to get on the subject of this. I deem you completed various fantastically good points in skin texture also.

  47. to read more说道:

    It as actually a cool and helpful piece of info. I am glad that you shared this useful info with us. Please keep us up to date like this. Thanks for sharing.

  48. more enjoyable for me to come here and visit more often.

  49. Thanks-a-mundo for the blog post.Really thank you! Awesome.

  50. There is definately a great deal to know about this issue. I really like all the points you have made.

  51. This really answered my problem, thank you!

  52. I wanted to thank you for this fantastic write-up, I certainly loved each and every small bit of it. I ave bookmarked your web site to look at the latest stuff you post.

  53. check out说道:

    I regard something really special in this site.

  54. visit说道:

    Say, you got a nice post.Really looking forward to read more. Great.

  55. write for us说道:

    Thanks for the news! Just was thinking about it! By the way Happy New Year to all of you:DD

  56. otlivy说道:

    Remarkable record! I ran across the idea same advantaging. Hard test in trade in a while in the direction of realize if further positions am real augment.

  57. more info说道:

    Im grateful for the article post.Really looking forward to read more. Really Cool.

  58. for more info说道:

    Rattling superb info can be found on blog.

  59. woh I enjoy your articles , saved to bookmarks !.

  60. Very interesting subject , regards for putting up.

  61. You ave made some decent points there. I looked on the web for additional information about the issue

  62. whites are thoroughly mixed. I personally believe any one of such totes

  63. Spot on with this write-up, I truly think this web site wants way more consideration. I?ll probably be once more to learn way more, thanks for that info.

  64. Wow, great blog.Thanks Again. Much obliged.

  65. Thanks-a-mundo for the blog.Much thanks again. Will read on

  66. Incredible story there. What happened after? Good luck!

  67. for more info说道:

    Just Browsing While I was browsing yesterday I saw a excellent article about

  68. I think other site proprietors should take this website as an model, very clean and fantastic user genial style and design, as well as the content. You are an expert in this topic!

  69. click here说道:

    Wow, wonderful blog structure! How lengthy have you ever been blogging for? you made blogging look easy. The total glance of your website is great, let alone the content material!

  70. Thanks again for the article.Thanks Again. Really Cool.

  71. IaаАа’б‚Т€ТšаЂаŒаАа’б‚Т€ТžаБТžd ought to seek advice from you here. Which is not something I do! I love reading an article that could make individuals feel. Also, several thanks permitting me to comment!

  72. moving home说道:

    Very informative blog article.Really looking forward to read more. Will read on…

  73. hamptonbay说道:

    Thank you for your article.Really thank you! Fantastic.

  74. Im thankful for the blog article.Really looking forward to read more. Great.

  75. Thanks a lot for the post.Really looking forward to read more. Will read on

  76. There is apparently a lot to know about this. I consider you made various good points in features also.

  77. official site说道:

    we came across a cool internet site that you just could love. Take a look should you want

  78. more info说道:

    rates my Website she admits she utilizes a secret weapon to help you shed weight on her walks.

  79. It is really a great and helpful piece of information. I am satisfied that you shared this helpful information with us. Please keep us informed like this. Thanks for sharing.

  80. When I look at your blog in Safari, it looks fine but

  81. genuine parts说道:

    It is really a great and useful piece of info. I am glad that you shared this useful info with us. Please keep us informed like this. Thank you for sharing.

  82. I went over this web site and I believe you have a lot of excellent information, saved to my bookmarks (:.

  83. The Birch of the Shadow I believe there may possibly become a several duplicates, but an exceedingly helpful checklist! I have tweeted this. Lots of thanks for sharing!

  84. Way cool! Some very valid points! I appreciate you penning this article plus the rest of the site is extremely good.

  85. Thanks-a-mundo for the article post.Really looking forward to read more. Awesome.

  86. Thanks again for the blog post.Thanks Again. Keep writing.

  87. Thanks for sharing, this is a fantastic blog.Really thank you! Awesome.

  88. Game Online说道:

    Usually I do not learn article on blogs, but I wish to say that this write-up very pressured me to try and do so! Your writing style has been surprised me. Thank you, quite great post.

  89. Canon 80d说道:

    Thank you for your post.Really thank you! Really Great.

  90. I think this is a real great article post.Thanks Again. Really Cool.

  91. we came across a cool website that you just may possibly delight in. Take a search when you want

  92. Some genuinely excellent articles on this website , thanks for contribution.

  93. This is a very good tip particularly to those new to the blogosphere. Short but very precise info Appreciate your sharing this one. A must read post!

  94. check out说道:

    You created some decent points there. I looked on line for that concern and located most of the people will go coupled with with all of your web site.

  95. iherbs说道:

    Wow, great article.Much thanks again. Want more.

  96. Thanks a lot for the article post.Really thank you! Great.

  97. Major thankies for the post.Really looking forward to read more. Really Great. buy viagra here

  98. this website说道:

    Its hard to find good help I am regularly proclaiming that its difficult to procure quality help, but here is

  99. Barcode Scanner说道:

    It as not that I want to replicate your web site, but I really like the design. Could you tell me which style are you using? Or was it tailor made?

  100. PRADA BAGS OUTLET ??????30????????????????5??????????????? | ????????

  101. This very blog is no doubt interesting additionally amusing. I have picked a bunch of useful tips out of this amazing blog. I ad love to visit it over and over again. Thanks a bunch!

  102. may bo dam说道:

    I value the blog.Really thank you! Fantastic.

  103. visit this site and be up to date all the time.

  104. I value the article.Much thanks again. Really Cool.

  105. why not try here说道:

    Very good article post.Really looking forward to read more.

  106. Im grateful for the post.Really looking forward to read more. Want more.

  107. This is a topic close to my heart cheers, where are your contact details though?

  108. Major thankies for the blog article.Much thanks again. Much obliged.

  109. You made some decent points there. I looked on the internet for more information about the issue and found most people will go along with your views on this website.

  110. jimmypromocode说道:

    We stumbled over here by a different website and thought I should check things out. I like what I see so now i am following you. Look forward to checking out your web page for a second time.

  111. mia pron khalifa说道:

    Wece24 Major thanks for the blog post.Really looking forward to read more. Keep writing.

  112. mia pron khalifa说道:

    sDIQTP Wow, superb blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is wonderful, as well as the content!

  113. arcadia realtor说道:

    Wow, that as what I was seeking for, what a material! existing here at this website, thanks admin of this website.

  114. Wow, great article.Really looking forward to read more. Great.

  115. Covina realtor说道:

    Usually I do not learn post on blogs, however I wish to say that this write-up very forced me to check out and do it! Your writing style has been surprised me. Thanks, quite nice post.

  116. This very blog is without a doubt awesome as well as factual. I have discovered a lot of handy things out of this amazing blog. I ad love to go back again soon. Thanks a bunch!

  117. Thanks-a-mundo for the article.Thanks Again. Really Great.

  118. This awesome blog is without a doubt entertaining as well as informative. I have chosen helluva interesting stuff out of this amazing blog. I ad love to visit it again and again. Thanks!

  119. I value the blog article.Thanks Again. Awesome.

  120. Very informative post.Much thanks again. Great.

  121. Its like you read my mind! You appear to know so much

  122. There as certainly a great deal to find out about this issue. I really like all the points you ave made.

  123. bistro masa说道:

    You have mentioned very interesting points ! ps nice website.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>