Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

maven-war-plugin ignores <archiveClasses>

The <archiveClasses> option has no effect.

Running mvn clean compile war:exploded produces a war directory with .class files in the classes directory, and they are not archived into a jar in the lib directory neither. war:war produces same result.

Plugin configuration:

...
<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.6</version>
  <configuration>
      <archiveClasses>true</archiveClasses>
  </configuration>
</plugin>
...

Workarounds?

Maven version 3.3.3, maven-war-plugin version 2.6.

JIRA ticket – https://issues.apache.org/jira/browse/MWAR-355

This is the project in question: https://bitbucket.org/dmos62/raudondvaris

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The first thing is you should move the plain configuration into a pluginManagement block like this:

 <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>2.6</version>
          <configuration>
            <archiveClasses>true</archiveClasses>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

If you do the above the classes will be created within the war archive by using: mvn clean compile war:war

~/ws-git/so-questions/so-5 (master)$ unzip -t target/web-1.0.0-SNAPSHOT.war
Archive:  target/web-1.0.0-SNAPSHOT.war
    testing: META-INF/                OK
    testing: META-INF/MANIFEST.MF     OK
    testing: WEB-INF/                 OK
    testing: WEB-INF/classes/         OK
    testing: WEB-INF/lib/             OK
    testing: WEB-INF/lib/commons-fileupload-1.1.1.jar   OK
    testing: WEB-INF/lib/commons-io-1.1.jar   OK
    testing: WEB-INF/lib/web-1.0.0-SNAPSHOT.jar   OK
    testing: WEB-INF/web.xml          OK
    testing: META-INF/maven/com.soebes.examples.so/web/pom.xml   OK
    testing: META-INF/maven/com.soebes.examples.so/web/pom.properties   OK
    testing: META-INF/INDEX.LIST      OK
No errors detected in compressed data of target/web-1.0.0-SNAPSHOT.war.

This will also working for your call mvn clean compile war:exploded.

   └── web-1.0.0-SNAPSHOT
        ├── META-INF
        └── WEB-INF
            ├── classes
            ├── lib
            │?? ├── commons-fileupload-1.1.1.jar
            │?? ├── commons-io-1.1.jar
            │?? └── web-1.0.0-SNAPSHOT.jar
            └── web.xml

The reason for this behaviour is simply cause by using a goal like war:war, or war:exploded there will be no life cycle started which means the configuration in the pom is not taken into account. If you like having a configuration for your command line calls you can do this by using a special configuration for command line calls like this (The id default-cli is the important part):

<project>
  <build>
    <plugins>
      <plugin>
        <groupId...>
        <artifactId...>
        <executions>
          <execution>
            <id>default-cli</id>
            <configuration>
              .....
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

which means having a special configuration for command line calls. Starting with Maven 3.3.1 it is possible having more than one configuration for command line calls by using it like:

<project...>
  <build>
    <plugins>
      <plugin>
        <groupId>...</groupId>
        <artifactId>...</artifactId>
        <executions>
          <execution>
            <id>first-cli</id>
            <configuration>
                 ....
            </configuration>
          </execution>
          <execution>
            <id>second-cli</id>
            <configuration>
                 ....
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

This can be used by maven via the following:

mvn plugin:goal@second-cli
mvn plugin:goal@first-cli

See also the release notes for Maven 3.3.1.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...