本文介绍了具有依赖库的Maven EJB打包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个问题,如何使用简单的WAR和EJB3模块为JBoss7应用服务器正确打包我的企业(EAR)应用程序。问题是,EJB模块正在使用XML-RPC库(来自Apache),并且在部署EAR期间我仍然获得NoDefClassFound(来自此xmlrpc lib的类)。

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.

问题是,maven- ejb -plugin在最终的EJB jar中执行包依赖关系,但是maven- ear -plugin会将它打包到根目录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.

当部署EAR时,在内部EJB模块上调用INSTALL但它找不到xmlrpc lib类(它没有与EJB jar一起包装但是EAR并没有它清单中的任何条目。)

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

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>

有没有办法如何使用maven彻底解决这个问题?

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

推荐答案

我设法解决了这个问题。似乎这些库必须打包在/ lib目录中,而不是在EAR的根目录中。添加defaultLibBundleDir元素解决了这个问题。

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.

例如:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
...

这篇关于具有依赖库的Maven EJB打包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:15