maven 2.2 war build不会将类放在关联的*-classes.jar文件中

Ric*_*d J 2 java maven-2 build maven

我正在尝试构建一个(war)项目,我从另一段代码中复制并修改了pom.xml文件,出于某种原因,当我mvn clean package在软件中它没有将类包含到关联的*-classes.jar中时文件.Ubuntu 12.10上的Maven版本是2.2.1.

我是maven的高手,主要通过复制和粘贴来管理示例,所以我基本上不知道我的pom是如何工作的(它完全包含在下面).

该项目有一个<packaging>war</packaging>元素,maven-war-plugin配置部分说到archiveClassesattachClasses,我认为这是导致构建*-classes.jar文件的原因.运行构建后,我的目标目录如下所示:

richard@holly:~/Code/External/JavaServer2.0/target$ ls 
apidocs  generated-sources  surefire           sword2-server-1.0-classes.jar  sword2-server-1.0-sources.jar
classes  maven-archiver     sword2-server-1.0  sword2-server-1.0-javadoc.jar  sword2-server-1.0.war
Run Code Online (Sandbox Code Playgroud)

但是sword2-server-1.0-classes.jar不包含任何类:

richard@holly:~/Code/External/JavaServer2.0/target$ jar tf sword2-server-1.0-classes.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/maven/
META-INF/maven/org.swordapp/
META-INF/maven/org.swordapp/sword2-server/
META-INF/maven/org.swordapp/sword2-server/pom.xml
META-INF/maven/org.swordapp/sword2-server/pom.properties
Run Code Online (Sandbox Code Playgroud)

同时,此目录中的所有其他*.jar文件都包含源文件的所有相关信息(javadocs,source等等,都已完成).

我毫无疑问错过了某种形式的插件配置,但到目前为止我无法理解maven插件文档,所以任何帮助都非常感激.

(几乎)完整的pom.xml(为简洁省略了实际的依赖关系):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>org.swordapp</groupId>
<artifactId>sword2-server</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<name>SWORD v2 :: Common Server Library</name>
<description>
    Common Server Library with interfaces to be implemented by servers
    wishing to provide SWORD v2 support
</description>
<url>http://www.swordapp.org/</url>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-release-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>6</source>
                <target>6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>
                            true
                        </addDefaultImplementationEntries>
                        <addDefaultSpecificationEntries>
                            true
                        </addDefaultSpecificationEntries>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
                <execution>
                    <id>default</id>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
                <execution>
                    <id>default</id>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <archiveClasses>true</archiveClasses>
                <attachClasses>true</attachClasses>
                <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
                <warSourceExcludes>WEB-INF/lib/*.jar</warSourceExcludes>
                <webResources>
                    <resource>
                        <filtering>true</filtering>
                        <directory>${basedir}/src/main/webapp</directory>
                        <includes>
                            <include>WEB-INF/web.xml</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    ....
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

Ric*_*d J 6

事实证明,archiveClassesattachClasses没有很好地在一起.该文档attachClasses说它将classes在战争构建期间将文件放在webapps 目录中的*-classes.jar中.但是将webapp中目录archiveClasses的内容classes放入webapp目录中的jar文件中lib.因为这意味着classes如果这两个配置标志都设置为true ,则目录中没有要放入*-classes.jar的类.

答案是archiveClasses从配置中删除,然后一切都按预期运行.

这似乎可能是一个maven bug,它在maven 2和maven 3中的行为相同.