8

Im facing an issue how to correctly package my enterprise (EAR) application with simple WAR and EJB3 module for JBoss7 application server. The thing is, that EJB module is using XML-RPC library (from Apache) and Im still getting NoDefClassFound (classes from this xmlrpc lib) during deployment of EAR.

The thing is, that maven-ejb-plugin does not package dependencies within final EJB jar but maven-ear-plugin does package it at the root of EAR directory.

When EAR gets deployed, INSTALL is invoked on inner EJB module but it does not find xmlrpc lib class (it is not packaged with EJB jar but EAR and it does not have any entry in manifest).

EJB 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>cz.ctu.fee.voxport.app_logic</groupId>
    <artifactId>core</artifactId>
    <version>1.0</version>
    <packaging>ejb</packaging>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlrpc</groupId>
            <artifactId>xmlrpc-common</artifactId>
            <version>3.1.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlrpc</groupId>
            <artifactId>xmlrpc-client</artifactId>
            <version>3.1.3</version>
        </dependency>
    </dependencies>

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

</project>

Is there any way how to cleanly solve this using maven?

user987339
  • 10,519
  • 8
  • 40
  • 45
zdenda.online
  • 2,451
  • 3
  • 23
  • 45

2 Answers2

10

I managed to solve the problem. It seems that these libraries has to be packaged within /lib directory and not in root of EAR. Adding defaultLibBundleDir element solved the problem.

E.g.:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
...
zdenda.online
  • 2,451
  • 3
  • 23
  • 45
  • If this is the answer that worked for you, please go ahead and mark it as the accepted answer to let future viewers know what worked for you. – Nightfirecat Nov 17 '11 at 21:51
  • i will accept, but I can do it in 19 hours (rules of stackoverflow) – zdenda.online Nov 17 '11 at 22:23
  • 3
    Did you leave the `true` on the EJB config? – Snekse Oct 24 '12 at 15:04
  • 1
    Sure, he must leave true on the EJB pom file to reference the packaged libraries in the EAR file – Samy Omar Oct 14 '15 at 18:45
  • Thanks for all following comments. Anyway these are kinda out of date as era of EARs is the past – zdenda.online Oct 14 '15 at 18:54
  • @d1x, why do you say EARs are out of date? I'm struggling with a similar problem - my remote interface library, which is a dependency of my EJB jar, isn't packaged in the jar (as http://stackoverflow.com/questions/28768762/building-deploying-a-ejb-jar-with-its-dependencies) - and the suggested approach seems to be to package everything in an EAR, as you did. What would be the alternative? – Michael Repucci Nov 13 '15 at 17:38
6

Did you leave the <addClasspath>true</addClasspath> on the EJB config?

Well, you can leave it like this, but you'll get a heap of log entries (WARN) on server start complaining about the classpath entries. I prefer to set it to false. <addClasspath>false</addClasspath>

Carsten
  • 61
  • 1
  • 1