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

June 9, 2011 by
Filed under: java 

首先在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>
Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Comments

2 Comments on maven打包web项目时同时打包为war和jar文件

  1. URL on Fri, 6th Jul 2012 2:50 am
  2. … [Trackback]…

    […] Read More: beyondlinux.com/2011/06/09/package_war_and_jar_on_maven_web_project/ […]…

  3. yx on Fri, 6th Jul 2012 11:05 am
  4. nice