Reputation: 7313
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. Maven version is 2.2.1 on Ubuntu 12.10.
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).
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. 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:
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).
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.
The (nearly) full pom.xml (omitted the actual dependencies for brevity):
<?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>
Upvotes: 2
Views: 7646
Reputation: 7313
It turns out that archiveClasses
and attachClasses
don't play well together. The documentation for attachClasses
says that it will put the files in the webapps classes
directory into a *-classes.jar during the war build. But archiveClasses
places the content of the classes
directory in the webapp into a jar file in the webapp's lib
directory. 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.
The answer is to remove archiveClasses
from the configuration, and then everything behaves as expected.
This seems like it's probably a maven bug, and it behaves the same in both maven 2 and maven 3.
Upvotes: 6
Reputation: 97427
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
Upvotes: 3