嗨,我有一个名为“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-war”称它为“myEngine”。我试图在“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告诉他不要部署相同的lib 3214899213次:)
答案 0 :(得分:0)
我建议在单独的jar中添加远程服务接口及其引用的所有类(包括异常)。然后在其他2个项目中声明对此jar的依赖。
I don't want it to be added as library and then deployed with the ear
我建议只添加service-lib包含接口等作为库并用耳朵部署它,而不是整个包含实现的service-ejb。