简体   繁体   English

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

[英]maven 2.2 war build does not put classes in associated *-classes.jar file

I'm trying to build a (war) project where I copied and modifed the pom.xml file from another piece of code, and for some reason when I mvn clean package the software it doesn't include the classes into the associated *-classes.jar file. 我正在尝试构建一个(war)项目,我从另一段代码复制并修改了pom.xml文件,出于某种原因,当我mvn clean package软件时,它不会将类包含在相关的*中 - classes.jar文件。 Maven version is 2.2.1 on Ubuntu 12.10. Ubuntu 12.10上的Maven版本是2.2.1。

I'm highly novice in maven, and largely manage by copy-and-paste from examples, so I basically have no idea how my pom works (it is included in full below). 我是maven的高手,主要是通过复制和粘贴来管理示例,所以我基本上不知道我的pom是如何工作的(它完全包含在下面)。

The project has a <packaging>war</packaging> element, and the maven-war-plugin configuration section says to archiveClasses and attachClasses , which I presume is what causes the *-classes.jar file to be built. 该项目有一个<packaging>war</packaging>元素, maven-war-plugin配置部分对archiveClassesattachClasses说,我认为这是导致构建* -classes.jar文件的原因。 Once I've run the build, my target directory looks as follows: 运行构建后,我的目标目录如下所示:

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

But the sword2-server-1.0-classes.jar doesn't contain any of the classes: 但是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

Meanwhile all the other *.jar files in this directory contain all the relevant information for the source files (javadocs, source, etc, are all complete). 同时,此目录中的所有其他* .jar文件都包含源文件的所有相关信息(javadocs,source等等,都已完成)。

I'm no doubt missing some form of plugin configuration, but am so far unable to make any sense of the maven plugin documentation, so any help hugely appreciated. 我毫无疑问错过了某种形式的插件配置,但到目前为止我无法理解maven插件文档,所以任何帮助都非常感激。

The (nearly) full pom.xml (omitted the actual dependencies for brevity): (几乎)完整的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>

It turns out that archiveClasses and attachClasses don't play well together. 事实证明, archiveClassesattachClasses并不能很好地协同工作。 The documentation for attachClasses says that it will put the files in the webapps classes directory into a *-classes.jar during the war build. attachClasses的文档说它会在战争构建期间将webapps classes目录中的文件放入* -classes.jar。 But archiveClasses places the content of the classes directory in the webapp into a jar file in the webapp's lib directory. 但是, archiveClasses将webapp中classes目录的内容放入webapp的lib目录中的jar文件中。 Since this means that there are no classes in the classes directory to be put into the *-classes.jar if both these configuration flags are set to true. 因为这意味着如果这两个配置标志都设置为true,那么classes目录中没有类要放入* -classes.jar中。

The answer is to remove archiveClasses from the configuration, and then everything behaves as expected. 答案是从配置中删除archiveClasses ,然后一切都按预期运行。

This seems like it's probably a maven bug, and it behaves the same in both maven 2 and maven 3. 这似乎可能是一个maven bug,它在maven 2和maven 3中的行为相同。

You should try to boil down the problem by reducing the complexity just try a simple configuration as follows first: 您应该尝试通过降低复杂性来解决问题,只需尝试简单的配置,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <archiveClasses>true</archiveClasses>
        <attachClasses>true</attachClasses>
    </configuration>
</plugin>

After that just try: 之后尝试:

mvn clean package

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM