当前位置: 代码迷 >> Web前端 >> maven封装web项目时同时打包为war和jar文件
  详细解决方案

maven封装web项目时同时打包为war和jar文件

热度:552   发布时间:2012-07-04 19:33:54.0
maven打包web项目时同时打包为war和jar文件
首先在pom.xml文件中指定war的打包方式,war

然后在pom文件的plugins节点下面增加如下内容即可mvn package时同时生成war, jar包。为了 mvn package install, mvn package deploy能够同时部署jar包,我们增加了后面2节点的配置:

<!--  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>