本文介绍了什么是GreeterEJB和GreeterLibrary之间的依赖关系的本质?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GreeterEJB 构建一个JAR,它不建立与依赖关系的libs文件夹:

When GreeterEJB builds as a JAR, it doesn't build with a libs folder for dependencies:

thufir@doge:~$ 
thufir@doge:~$ ll NetBeansProjects/GreeterEJB/dist/
total 20
drwxrwxr-x 2 thufir thufir 4096 Feb 25 14:34 ./
drwxrwxr-x 6 thufir thufir 4096 Feb 25 14:34 ../
-rw-rw-r-- 1 thufir thufir 2802 Feb 25 14:34 GreeterEJB.jar
thufir@doge:~$ 

然而,当部署,Glassfish的提供了以下错误:

However, when it deploys, Glassfish gives the following error:

Error in annotation processing: {0}.
java.lang.NoClassDefFoundError: net/bounceme/doge/greeter/ejb/GreeterRemote

因为,我认为,它无法找到 GreeterRemote 类,这个类是在不同的JAR:

because, I think, it can't find the GreeterRemote class, as that class is in a different JAR:

thufir@doge:~$ 
thufir@doge:~$ jar -tf NetBeansProjects/GreeterLibrary/dist/GreeterLibrary.jar | grep class
net/bounceme/doge/greeter/ejb/GreeterRemote.class
thufir@doge:~$ 

这是什么依赖的自然?这是怎么从添加类项目的类路径有什么不同?至少在Netbeans的时候,例如,JDBC驱动程序添加到类路径,该驱动程序将在libs文件夹旁边这是生成JAR露面。

What's the nature of this dependency? How is this different from adding a class to the classpath of project? At least in Netbeans, when, for example, a JDBC driver is added to the classpath, that driver will show up in the libs folder alongside the JAR which was built.

在EJB:

package net.bounceme.doge.greeter.ejb;

import javax.ejb.Stateless;

@Stateless
public class GreeterBean implements GreeterRemote {

    @Override
    public String greeting() {
        return "hello remote world";
    }

}

迎宾远程接口:

package net.bounceme.doge.greeter.ejb;

import javax.ejb.Remote;

@Remote
public interface GreeterRemote {

    String greeting();

}

该GreeterLibrary JAR文件添加到Glassfish的:

The GreeterLibrary JAR file added to glassfish:

thufir@doge:~$ 
thufir@doge:~$ ll glassfish-4.1/glassfish/lib/*.jar
-rw-r--r-- 1 thufir thufir    2694 Feb 22 18:56 glassfish-4.1/glassfish/lib/appserv-rt.jar
-rw-rw-r-- 1 thufir thufir   20020 Feb 25 06:06 glassfish-4.1/glassfish/lib/EJBRemoteInterface.jar
-rw-r--r-- 1 thufir thufir   22189 Feb 22 18:56 glassfish-4.1/glassfish/lib/gf-client.jar
-rw-r--r-- 1 thufir thufir    3193 Feb 22 18:56 glassfish-4.1/glassfish/lib/javaee.jar
-rw-r--r-- 1 thufir thufir    1398 Feb 22 18:56 glassfish-4.1/glassfish/lib/jndi-properties.jar
-rw-r--r-- 1 thufir thufir 1006015 Feb 23 16:58 glassfish-4.1/glassfish/lib/mysql-connector-java.jar
thufir@doge:~$ 
thufir@doge:~$ ll glassfish-4.1/glassfish/domains/domain1/lib/*.jar
-rw-rw-r-- 1 thufir thufir 20020 Feb 25 06:06 glassfish-4.1/glassfish/domains/domain1/lib/EJBRemoteInterface.jar
thufir@doge:~$ 
thufir@doge:~$ ll glassfish-4.1/glassfish/domains/domain1/lib/classes/*.jar
-rw-rw-r-- 1 thufir thufir 20020 Feb 25 06:06 glassfish-4.1/glassfish/domains/domain1/lib/classes/EJBRemoteInterface.jar
thufir@doge:~$ 


我记得做与远程接口,但我似乎已经忘记了与远程接口的关键一步,而在此刻,无法找到合适的谷歌条款。我敢肯定的地方在GlassFish手册有关于EJB相关性的部分,他们去哪里...


I recall doing something like this before with remote interfaces, but I seem to have forgotten a key step with the remote interface, and, at the moment, cannot find the right Google terms. I'm sure somewhere in the Glassfish manual there's a section on EJB dependencies and where they go...

现在,我只想知道在自然类型的依赖性是这样的话,我至少知道什么谷歌的。

Right now, I just want to know the nature or type of dependency this is so that I at least know what to Google for.

推荐答案

您不想把你自己开发的Glassfish的lib文件夹里面的依赖关系。这可能是足够的用于生产使用,而不是用于开发。

You don't want to place the dependencies you developed on your own inside the Glassfish lib folder. This may be sufficient for productive usage, but not for development.

要这样做的权利,你需要一个EAR。

To do it right, you need an EAR.

耳内,你可以为你的依赖关系创建一个 LIB 文件夹中。

Inside the EAR, you can create a lib folder for your dependencies.

耳结构将类似于此:

/EAR
/EAR/GreeterEJB.jar
/EAR/lib
/EAR/lib/GreeterLibrary.jar

这篇关于什么是GreeterEJB和GreeterLibrary之间的依赖关系的本质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 18:40