是否可以使用 GlassFish 在 domain1/lib 中包含 EJB?
Is it possible to have EJBs in domain1/lib using GlassFish?
我使用 GlassFish 4 Web 配置文件,我有以下界面和 class。
@Local
public interface SomeService {
...
}
@Singleton
public class SomeServiceBean implements SomeService {
...
}
当我将接口和 class 放入 .war 存档(即 domain1/autodeplay 中)时,一切正常。但是,当我将接口和 class 放在单独的 .jar 存档中(即在 domain1/lib 中)然后部署 war 应用程序时,我得到:
java.lang.RuntimeException: Cannot resolve reference Local ejb-ref name=com.temp.MyServlet/someService,Local 3.x interface =com.temp.SomeService,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session
at com.sun.enterprise.deployment.util.ComponentValidator.accept(ComponentValidator.java:374) ~[dol.jar:na]
at com.sun.enterprise.deployment.util.DefaultDOLVisitor.accept(DefaultDOLVisitor.java:78) ~[dol.jar:na]
at com.sun.enterprise.deployment.util.ComponentValidator.accept(ComponentValidator.java:123) ~[dol.jar:na]
at com.sun.enterprise.deployment.util.ApplicationValidator.accept(ApplicationValidator.java:152) ~[dol.jar:n
...
我不使用任何 xml 描述符。那么,是否可以在 domain1/lib 中包含 EJB?如果可以,如何让 EJB 容器找到它们? P.S。我在 GF 4 中试过了 - 结果是一样的。
EJB 不能作为库添加到 GlassFish,库只是添加到类路径,它们上的任何注释都将被忽略,它们不会通过 EJB 容器。如果您确实希望将 EJB 作为单独的 JAR,则可以像 WAR 或 EAR 文件一样部署它们。
在 Glassfish reference manual 中,add-library
命令表示 "adds the library to the class loader directory",而 deploy
命令表示 "Applications can be...EJB modules"。
也可以通过查看 source code for Glassfish it can be worked out that all libraries are simply added to the Classloader either at launch (See here and here) or if in applibs then when the application is deployed (See here).
我使用 GlassFish 4 Web 配置文件,我有以下界面和 class。
@Local
public interface SomeService {
...
}
@Singleton
public class SomeServiceBean implements SomeService {
...
}
当我将接口和 class 放入 .war 存档(即 domain1/autodeplay 中)时,一切正常。但是,当我将接口和 class 放在单独的 .jar 存档中(即在 domain1/lib 中)然后部署 war 应用程序时,我得到:
java.lang.RuntimeException: Cannot resolve reference Local ejb-ref name=com.temp.MyServlet/someService,Local 3.x interface =com.temp.SomeService,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session
at com.sun.enterprise.deployment.util.ComponentValidator.accept(ComponentValidator.java:374) ~[dol.jar:na]
at com.sun.enterprise.deployment.util.DefaultDOLVisitor.accept(DefaultDOLVisitor.java:78) ~[dol.jar:na]
at com.sun.enterprise.deployment.util.ComponentValidator.accept(ComponentValidator.java:123) ~[dol.jar:na]
at com.sun.enterprise.deployment.util.ApplicationValidator.accept(ApplicationValidator.java:152) ~[dol.jar:n
...
我不使用任何 xml 描述符。那么,是否可以在 domain1/lib 中包含 EJB?如果可以,如何让 EJB 容器找到它们? P.S。我在 GF 4 中试过了 - 结果是一样的。
EJB 不能作为库添加到 GlassFish,库只是添加到类路径,它们上的任何注释都将被忽略,它们不会通过 EJB 容器。如果您确实希望将 EJB 作为单独的 JAR,则可以像 WAR 或 EAR 文件一样部署它们。
在 Glassfish reference manual 中,add-library
命令表示 "adds the library to the class loader directory",而 deploy
命令表示 "Applications can be...EJB modules"。
也可以通过查看 source code for Glassfish it can be worked out that all libraries are simply added to the Classloader either at launch (See here and here) or if in applibs then when the application is deployed (See here).