本文介绍了maven打包web项目时同时打包为war和jar文件的方法,分享给大家,具体如下:
首先在pom.xml文件中指定war的打包方式,war
1
2
3
|
< artifactId >test</ artifactId >
< name >test</ name >
< packaging >war</ packaging >
|
上述代码在eclipse中执行maven install时, 会默认打成war,并放入本地仓库。
web项目时同时打包为war和jar文件
1、首先添加在pom.xml中添加插件 maven-jar-plugin , 使得 在调用命令mvn package install 或者 mvn package deploy 先生成 jar包。或者使用mvn package生成jar包。该插件生成的架包会放在工程的target文件夹下。
2、然后配置maven-install-plugin 插件, 使得在eclipse中执行maven install时, 同时生成jar和war到本地仓库。
3、再配置org.apache.maven.plugins插件, 使得在eclipse中执行deploy 时, 同时,生成jar和war到远程仓库。
源码如下:
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<!-- package jar on package -->
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-jar-plugin</ artifactId >
< executions >
< execution >
< phase >compile</ phase >
< goals >
< goal >jar</ goal >
</ goals >
</ execution >
</ executions >
</ plugin >
<!-- install jar to local repository -->
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-install-plugin</ artifactId >
< executions >
< execution >
< phase >install</ phase >
< goals >
< goal >install-file</ goal >
</ goals >
< configuration >
< packaging >jar</ packaging >
< artifactId >${project.artifactId}</ artifactId >
< groupId >${project.groupId}</ groupId >
< version >${project.version}</ version >
< file >
${project.build.directory}/${project.artifactId}-${project.version}.jar
</ file >
</ configuration >
</ execution >
</ executions >
</ plugin >
<!-- deploy jar to remote repository -->
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-deploy-plugin</ artifactId >
< executions >
< execution >
< phase >deploy</ phase >
< goals >
< goal >deploy-file</ goal >
</ goals >
< configuration >
< packaging >jar</ packaging >
< generatePom >true</ generatePom >
< url >${project.distributionManagement.repository.url}</ url >
< artifactId >${project.artifactId}</ artifactId >
< groupId >${project.groupId}</ groupId >
< version >${project.version}</ version >
< file >${project.build.directory}/${project.artifactId}.jar</ file >
</ configuration >
</ execution >
</ executions >
</ plugin >
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://blog.csdn.net/xlxxcc/article/details/52623855