首先在pom.xml文件中指定war的打包方式,war
然后在pom文件的plugins节点下面增加如下内容即可mvn package时同时生成war, jar包。为了 mvn package install, mvn package deploy能够同时部署jar包,我们增加了后面2节点的配置:
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 58 | <!-- package jar on package --> < plugin > < groupId >org.apache.maven.plugins</ groupId > < artifactId >maven-jar-plugin</ artifactId > < executions > < execution > < id >make-a-jar</ id > < 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 > |
最后,发布到远程仓库 插件可以按自己需要屏蔽。