2014-10-31 92 views
1

我想用maven构建一个groovy项目。我的包装类型是war文件。 Maven正在构建项目并将所有相关库放在WEB-INF/lib文件夹中,但它将所有代码编译成类文件并将其放入WEB-INF/classes文件夹中。有没有一种方法可以告诉maven为我的项目构建jar文件并将其放入WEB-INF/lib文件夹中。maven - 如何编译代码到jar文件而不是.class

我的pom.xml看起来是这样的:

<groupId>com.myproject</groupId> 
<artifactId>ExampleProject</artifactId> 
<version>1.0.0-SNAPSHOT</version> 
<packaging>war</packaging> 
<name>My Example Project</name> 
<url>http://maven.apache.org</url> 
<dependencies> 

... 
... 
... 
</dependencies> 
<build> 
    <resources> 
     <resource> 
      <directory>${basedir}/src/main/groovy</directory> 
      <excludes> 
       <exclude>**/*.groovy</exclude> 
      </excludes> 
     </resource> 
     <resource> 
      <directory>${basedir}/src/main/resources</directory> 
     </resource> 
    </resources> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>build-helper-maven-plugin</artifactId> 
      <version>1.5</version> 
      <executions> 
       <execution> 
        <id>add-source</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>add-source</goal> 
        </goals> 
        <configuration> 
         <sources> 
          <source>src/main/groovy</source> 
          <source>src/main/resources</source> 
         </sources> 
        </configuration> 
       </execution> 
       <execution> 
        <id>add-test-source</id> 
        <phase>generate-test-sources</phase> 
        <goals> 
         <goal>add-test-source</goal> 
        </goals> 
        <configuration> 
         <sources> 
          <source>src/test/groovy</source> 
          <source>src/test/resources</source> 
         </sources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
    <finalName>master</finalName> 
</build> 

回答

1

在这些情况下通常的做法是你在一个不同的模块,这将是从你的战模块的依赖分开你的库代码。对于这个建议,你也可以看到how to generate jar and war both in project

不过,如果你还是喜欢去与你提到的解决方案,你可以用下面的配置做它在你的POM

<configuration> 
    .. 
    <attachClasses>true</attachClasses> 
    <archiveClasses>true</archiveClasses> 
</configuration> 

(见http://maven.apache.org/plugins/maven-war-plugin/war-mojo.htmlhow to use class file from another war