【问题标题】:netbeans 7-8, inject of remote ejbnetbeans 7-8,远程ejb注入
【发布时间】:2014-03-27 18:31:05
【问题描述】:

嗨,我有一个名为“service-ejb”的 EJB 项目:

@Stateless
@Remote(ServiceRemote.class)
public class Services implements ServiceLocal, ServiceRemote {
  [...business code...]
}

我有本地界面,在同一个项目中:

@Local
public interface ServiceLocal { }

和远程接口,在一个名为“service-lib”的类库项目中:

@Remote
public interface ServiceRemote {
  public boolean checkIfOk();
}

我可以毫无问题地单独或在 Java EE 应用程序中部署它。关键是我不明白如何告诉 NetBeans 我希望从另一个应用程序调用该 bean。例如,我有另一个带有 war 组件的 java EE 项目,我在 servlet 中写道:

@EJB
private ServiceRemote serviceTest;

当然它会编译失败,所以我尝试了:

InitialContext ic = new InitialContext();
ServiceRemote serviceTest = (ServiceRemote) ic.lookup("ServiceRemote");    

没有运气...在 NetBeans 中我可以告诉它使用“service-lib”作为参考吗?我不希望它被添加为库然后用耳朵部署,我只希望 NetBeans 正确编译代码。

对不起,如果这个问题听起来很愚蠢,但我已经阅读了文档,但我不明白我错过了什么......

--- 编辑---

我会尽量说得更清楚。 “service-ejb”引用“service-lib”,所以我已将“service-ejb”部署到 glassfish。没错,我有:

glassfish_applications_directory $ find -name "service*"
./__internal/service-ejb
./__internal/service-ejb/service-ejb.jar
./service-ejb
./service-ejb/com/tecytal/components/email/beans/Service.class
./service-ejb/com/tecytal/components/email/interfaces/local/ServiceLocal.class
./service-ejb/service-lib.jar

然后我打开一个 java EE 项目,我们称它为“myEngine”,带有一个战争模块“myEngine-war”。当然,我尝试向“myEngine-war”添加对“service-lib”的引用,在这种情况下它编译得很好。关键是我可以做任何事情,告诉netbeans不要将“service-lib”与战争打包,但是当我部署“myEngine”时,我得到:

glassfish_applications_directory $ find -name "service*"
./myEngine/lib/service-lib.jar
./__internal/service-ejb
./__internal/service-ejb/service-ejb.jar
./service-ejb
./service-ejb/com/tecytal/components/email/beans/Service.class
./service-ejb/com/tecytal/components/email/interfaces/local/ServiceLocal.class
./service-ejb/service-lib.jar

我不想在我的服务器中有两个 service-lib.jar,一个在 service-ejb 中,一个在 myEngine 中,我不明白如何在 netbeans 中使用远程 ebj 告诉他不要部署相同的库 3214899213 次 :)

【问题讨论】:

    标签: java jakarta-ee netbeans ejb


    【解决方案1】:

    我建议将远程服务接口及其引用的所有类(包括异常)添加到单独的 jar 中。然后在其他 2 个项目中声明对这个 jar 的依赖。

    I don't want it to be added as library and then deployed with the ear
    

    我建议只添加包含接口等的服务库作为库并使用 ear 部署它,而不是包含实现的整个 service-ejb。

    【讨论】:

    • 对不起,我不明白。 service-lib 包含远程接口和所有需要的类(传输等),我尝试将 service-lib 项目添加到客户端应用程序(激活包选项但未激活),但部署总是失败,并显示“zip 文件是空 -- 无效的 zip 文件 ... service-lib.jar"。如果我必须将它打包到我的项目中,那么有可能调用远程 ejb 有什么意义
    • 只打包远程接口等,不打包实现。
    • 所以,我误解了一些东西:要远程调用 ejb,我必须打包远程接口是或是,所以如果我有 100 个使用“服务”的应用程序,我将有 100 个远程服务副本界面,对吗?
    • 是的,没错,AFAIK(我还没有从另一个 Java EE 应用程序调用远程 EJB。)只要确保远程接口(以及 DTO、异常等)位于单独的jar,因此您可以简单地将整个 jar 打包到您的 EAR/WAR 文件中。
    猜你喜欢
    • 2012-05-11
    • 2012-01-01
    • 1970-01-01
    • 2015-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    相关资源
    最近更新 更多