I am using Maven to build an EAR project with 20+ artifacts and ~30 3rd party artifacts. The EAR structure looks like this
EAR
+-project-artifact-1
+-project-artifact-2
...
+-project-artifact-n
+-lib/
| +-3rd-party-lib-1
| +-3rd-party-lib-2
| ...
| \-3rd-party-lib-n
\-META-INF/
packaging works fine. My problem is with the customization of the Class-Path for the MANIFEST.MF I want to use Mavens feature to create the MANIFEST.MF for me by using
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
I know I can use the classpathPrefix
to set a prefix, but this prefix will be added to all dependencies, regardless of their location.
For technical reasons, I cannot put all my JAR type artifacts in the lib folder.
The only workaround for this would be to set my project-artifact dependencies to scope provided
and add them manually to the class path with manifestEntries
.
I do not like this workaround, as it is hard to maintain and effectively kills the transitivity of my dependencies (and I want to keep that).
I found this example for a custom class-path but I don't see how I can use it for my purpose. My idea was to use a property to manipulate the class-path, but it seems that you can only use certain attributes of the artifact as variables.
Is there any other way to build the CP (except using a manually maintained MF or manually maintaining the CP entries in the poms)?
this is what my parent pom looks like (shortened):
<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>com.my.app</groupId>
<artifactId>build-parent</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<name>build parent</name>
<description>
</description>
<repositories>
<repository>
<id>myapp-internal</id>
<url>file:///${user.home}/.m2/repository</url>
<releases>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
</repository>
</repositories>
<properties>
<!-- variables -->
<!-- myapp -->
<myapp.version>0.1</myapp.version>
<myapp.encoding>Cp1252</myapp.encoding>
<!-- config variables -->
<directory.target>../myapp_build/target</directory.target>
<version.ejb>3.1</version.ejb>
<!-- 3rd party lib versions -->
<version.slf4j>1.7.10</version.slf4j>
<!-- maven plugin versions -->
<version.plugin.buildhelper>1.3</version.plugin.buildhelper>
<version.plugin.maven.assambley>2.2.1</version.plugin.maven.assambley>
<version.plugin.maven.compiler>3.1</version.plugin.maven.compiler>
<version.plugin.maven.ear>2.9.1</version.plugin.maven.ear>
<version.plugin.maven.ejb>2.3</version.plugin.maven.ejb>
<version.plugin.maven.jar>2.4</version.plugin.maven.jar>
<version.plugin.maven.war>2.4</version.plugin.maven.war>
<!-- settings -->
<project.build.sourceEncoding>${myapp.encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${myapp.encoding}</project.reporting.outputEncoding>
</properties>
<!-- define default dependency details -->
<dependencyManagement>
<dependencies>
<!-- myapp dependencies -->
<!-- com.my.app -->
<dependency>
<groupId>com.my.app</groupId>
<artifactId>artifact1</artifactId>
<version>${myapp.version}</version>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>artifact2</artifactId>
<version>${myapp.version}</version>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>myapp_ejb</artifactId>
<version>${myapp.version}</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>myapp_web</artifactId>
<version>${myapp.version}</version>
<type>war</type>
</dependency>
<!-- 3rd party dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${version.slf4j}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>${version.slf4j}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<!-- use Eclipse style structure -->
<sourceDirectory>src</sourceDirectory>
<outputDirectory>bin</outputDirectory>
<!-- target -->
<directory>${directory.target}</directory>
<!-- define default plugin settings -->
<pluginManagement>
<plugins>
<!-- assambley -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${version.plugin.maven.assambley}</version>
</plugin>
<!-- build helper -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${version.plugin.buildhelper}</version>
</plugin>
<!-- compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.plugin.maven.compiler}</version>
<configuration>
<source>${version.java}</source>
<target>${version.java}</target>
</configuration>
</plugin>
<!-- ear -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.plugin.maven.ear}</version>
</plugin>
<!-- ejb -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>${version.plugin.maven.ejb}</version>
<configuration>
<ejbVersion>${version.ejb}</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<!-- jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${version.plugin.maven.jar}</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</archive>
</configuration>
</plugin>
<!-- war -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${version.plugin.maven.war}</version>
<configuration>
<!-- use provided web.xml -->
<webXml>WebContent/WEB-INF/web.xml</webXml>
<!-- ressources location -->
<warSourceDirectory>WebContent</warSourceDirectory>
<!-- build a skinny WAR -->
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
this is my (shortened) pom for the EAR:
<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>
<parent>
<groupId>com.my.app</groupId>
<artifactId>build-parent</artifactId>
<version>0.1</version>
<relativePath>../myapp_build</relativePath>
</parent>
<groupId>com.my.app</groupId>
<artifactId>myapp_application_EAR</artifactId>
<version>${myapp.version}</version>
<description />
<packaging>ear</packaging>
<dependencies>
<!-- myapp dependencies -->
<dependency>
<groupId>com.my.app</groupId>
<artifactId>myapp_web</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>myapp_ejb</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>artifact1</artifactId>
</dependency>
<dependency>
<groupId>com.my.app</groupId>
<artifactId>artifact2</artifactId>
</dependency>
<!-- 3rd party dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<generateApplicationXml>true</generateApplicationXml>
<!-- skinny WAR configuration see WAR project POM -->
<skinnyWars>true</skinnyWars>
<modules>
<webModule>
<groupId>com.my.app</groupId>
<artifactId>myapp_web</artifactId>
<contextRoot>myapp_web</contextRoot>
</webModule>
<ejbModule>
<groupId>com.my.app</groupId>
<artifactId>myapp_ejb</artifactId>
</ejbModule>
<!-- 3rd party libs go to lib/ -->
<jarModule>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<bundleDir>lib/</bundleDir>
<includeInApplicationXml>false</includeInApplicationXml>
</jarModule>
<jarModule>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<bundleDir>lib/</bundleDir>
<includeInApplicationXml>false</includeInApplicationXml>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>