How do I correctly use SNAPSHOTS dependencies with EARs and EJBs
Asked Answered
I

2

4

I am trying to build an EJB in an EAR. My EJB has dependencies on SNAPSHOTS. So when I build the EAR my structure looks like this:

my-ear-1.0.0-SNAPSHOT.ear
 + META-INF  
  - application.xml
  - MANIFEST.MF
 - my-ejb-1.0.0-SNAPSHOT.jar
 - third-party-lib-1.0.0-SNAPSHOT.jar

However, when using the maven-ejb-plugin to generate its MANIFEST.MF:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-ejb-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
      </manifest>
    </archive>
  </configuration>
</plugin>

The problem I have, is the MANIFEST.MF lists the SNAPSHOT as how it appears in Nexus which is not how the maven-ear-plugin named it when building the ear.

Manifest-Version: 1.0
Build-Jdk: 1.6.0_25
Class-Path: third-party-lib-1.0.0-20121026.140152-21.jar

So of course I'm getting ClassNotFoundException s because the EJBs classpath is looking for a jar file that doesn't exist.

Basically I need to know either:

  1. How do I get the maven-ear-plugin to pull in the jars into the ear without the -SNAPSHOT format?
  2. How do I get the maven-ejb-plugin to use the -SNAPSHOT format in the MANIFEST.MF?
Intellectuality answered 26/10, 2012 at 16:6 Comment(0)
I
11

I found the solution to my problem by looking through the maven archiver documentation at Maven Archiver - Handling Snapshots.

I just needed to configure my maven-ejb-plugin so that it didn't use "unique versions":

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>                           
                        <useUniqueVersions>false</useUniqueVersions>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

RTFM closer next time I guess :)

Intellectuality answered 26/10, 2012 at 16:53 Comment(1)
I had similar issue with maven-jar-plugin and similarly <useUniqueVersions>false</useUniqueVersions> was the fix, cheers.Hapsburg
D
0

Using Maven version 3.6.2.

Below configuration of maven-ear-plugin solved my issue.

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-ear-plugin</artifactId>
      <version>3.0.1</version>
      <configuration>
        <outputFileNameMapping>@{artifactId}@-@{baseVersion}@@{dashClassifier?}@.@{extension}@</outputFileNameMapping>
        <generateApplicationXml>true</generateApplicationXml>
        <version>7</version>
      </configuration>
    </plugin>

if required you can also change the format of outputFileNameMapping but use baseVersion to solve this timestamp issue.

Dorothy answered 28/5, 2020 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.