Maven EJB packaging with dependent libraries
Asked Answered
W

2

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?

Wortman answered 16/11, 2011 at 17:39 Comment(7)
Please post relevant portions of your POM.Hornmad
Maybe a dependency with <scope>provided</scope>?Lakitalaks
scope provided where? On EJB jar? That does not add entry to classpath (when using maven-ejb-plugin) and even not jar to package.Wortman
It seems I managed to have xmlrpc jar (using maven-dependency-plugin) and entry in manifest both in EJB jar. But Im still getting NoClassDefFoundError. Am I missing something?Wortman
Can you post the complete exception?Liszt
Note that NoClassDefFoundErrors often indicate that one of the classes that is available on your classpath references one that isn't available, and the class listed in the exception message is not necessarily the one missing (unlike ClassNotFoundExceptions).Liszt
Thanks shelley. I solved the problem, see the response belowWortman
W
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>
...
Wortman answered 17/11, 2011 at 10:55 Comment(6)
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.Timi
i will accept, but I can do it in 19 hours (rules of stackoverflow)Wortman
Did you leave the <addClasspath>true</addClasspath> on the EJB config?Myocardiograph
Sure, he must leave <addClasspath>true</addClasspath> on the EJB pom file to reference the packaged libraries in the EAR fileBosporus
Thanks for all following comments. Anyway these are kinda out of date as era of EARs is the pastWortman
@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 #28769262) - and the suggested approach seems to be to package everything in an EAR, as you did. What would be the alternative?Timisoara
J
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>

Jdavie answered 11/12, 2012 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.