如何使用Maven构建和部署远程EJB

如何使用Maven构建和部署远程EJB

本文介绍了如何使用Maven构建和部署远程EJB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Maven构建和部署远程EJB。后来,我想要将这个EJB注入并使用到一个单独的WAR项目中。

I want to use Maven to build and deploy a Remote EJB. Later, I'll want to be able to inject and use this EJB into a separate WAR project.

所以我以为我需要一个定义界面的jar文件,并在两个项目中使用jar(ejb和war)。

So I thought I'll need a jar file that defines the interface, and use the jar in both projects (ejb and war).

我有一个名为的Maven项目的界面,例如:api ,打包成jar:

I have this interface, in a Maven project called example:api, packaged as jar:

package example;

import javax.ejb.Remote;

@Remote
public interface Bean {

    void process();
}

我在另一个名为的Maven项目中实现上述界面例如:ejb ,打包为ejb:

I implement the above interface in another Maven project called example:ejb, packaged as ejb:

package example;

import javax.ejb.Stateless;

@Stateless
public class Ejb implements Bean {

    @Override
    public void process() {
    }
}

ejb项目使用 maven-ejb-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ejb-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <ejbVersion>3.1</ejbVersion>
    </configuration>
</plugin>

这两个项目都依赖于 javaee-api

And both projects depend on javaee-api:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

现在把它们放在一起,我创建了一个名为的第三个Maven项目:ear ,打包成 ear

Now to put them together, I made a third Maven project, called example:ear, packaged as 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>
    <groupId>example</groupId>
    <artifactId>ear</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>ear</packaging>
    <name>ear</name>

    <dependencies>
        <dependency>
            <groupId>example</groupId>
            <artifactId>api</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>example</groupId>
            <artifactId>ejb</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>ejb</type>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <configuration>
                    <modules>
                        <ejbModule>
                            <groupId>example</groupId>
                            <artifactId>ejb</artifactId>
                        </ejbModule>
                        <jarModule>
                            <groupId>example</groupId>
                            <artifactId>api</artifactId>
                        </jarModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

问题是我无法部署此耳机项目。我收到以下错误:

The problem is that I can't deploy this ear project. I get the following error:

09:39:39,702 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) JBAS015003: Found ear.ear in deployment directory. To trigger deployment create a file called ear.ear.dodeploy
09:39:39,713 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "ear.ear"
09:39:39,773 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "ejb-0.0.1-SNAPSHOT.jar"
09:39:39,793 WARN  [org.jboss.modules] (MSC service thread 1-8) Failed to define class example.Ejb in Module "deployment.ear.ear.ejb-0.0.1-SNAPSHOT.jar:main" from Service Module Loader: java.lang.LinkageError: Failed to link example/Ejb (Module "deployment.ear.ear.ejb-0.0.1-SNAPSHOT.jar:main" from Service Module Loader)
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396)
[...]
Caused by: java.lang.NoClassDefFoundError: example/Bean
    at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_03]
[...]
Caused by: java.lang.ClassNotFoundException: example.Bean from [Module "deployment.ear.ear.ejb-0.0.1-SNAPSHOT.jar:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

我正在使用JBoss AS 7.1.1,如果有任何区别。

I'm using JBoss AS 7.1.1, if it makes any difference.

你知道我在做什么错吗?

Do you know what I'm doing wrong?

推荐答案

我更改了 maven-ear-插件

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

这样就可以了。

这篇关于如何使用Maven构建和部署远程EJB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 21:30