T
T
tavi2014-06-25 17:07:57
Java
tavi, 2014-06-25 17:07:57

Migration from JBoss 6 to JBoss 7 - why is EJB not visible from WAR?

I have a project that consists of one EJB and one WAR using the EJB methods through the local interface. Under JBoss 6 they worked great together. Under JBoss 7 - do not want to.
EJB declares an interface named DBLocal (it is used to access the database) and successfully deploys under Jboss7, writes the following JNDI bindings to the console:

java:global/ru.test.ejb.orm/DBBean!ru.test.ecm.orm.bean.DBLocal
  java:app/ru.test.ejb.orm/DBBean!ru.test.ecm.orm.bean.DBLocal
  java:module/DBBean!ru.test.ecm.orm.bean.DBLocal
  java:global/ru.test.ejb.orm/DBBean
  java:app/ru.test.ejb.orm/DBBean
  java:module/DBBean

The server code in the WAR file says this:
//Это некий класс сервлета
public class LoginServiceImpl extends RemoteServiceServlet implements LoginService, ServletContextListener
{
        //Вот он, EJB-шник:
  @EJB(lookup="java:global/ru.test.ejb.orm/DBBean!ru.test.ecm.orm.bean.DBLocal")
  private DBLocal dbBean;
       ...
}

Does not work. JBoss 7 cannot detect EJBs, writes the following errors to the console:
Caused by: java.lang.NoClassDefFoundError: Lru/test/ecm/orm/bean/DBLocal;
  at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.7.0_25]
  at java.lang.Class.privateGetDeclaredFields(Unknown Source) [rt.jar:1.7.0_25]
  at java.lang.Class.getDeclaredFields(Unknown Source) [rt.jar:1.7.0_25]
  at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
  at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:68) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
  ... 10 more
Caused by: java.lang.ClassNotFoundException: ru.test.ecm.orm.bean.DBLocal from [Module "deployment.ecm.war:main" from Service Module Loader]
  at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final-redhat-2]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final-redhat-2]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final-redhat-2]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final-redhat-2]
  at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final-redhat-2]
  ... 15 more

Those. it cannot refer to a class declared inside an EJB module. Reading the documentation didn't help me much. There is a way to overcome NoClassDefFoundError by including the EJB module as a library (by putting it in the WEB-INF/lib folder in the WAR), but then it is used as a simple plugin library, as I understand it. If I deploy several WARs on the server that use the same EJB, each will use its own EJB instance, which is not great (strictly speaking, it will no longer be an EJB).
How do you get WAR to see the EJB and work with it in the normal way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Smirnov, 2014-06-26
@tavi

project consisting of one EJB and one WAR
In JBoss (and in JEE application server terminology in general) there is no concept of a "project". Do I understand correctly that "project" means Enterprise Archive (EAR)? If you don't have an EAR, then I don't see any way to treat a separate WAR and a separate EJB module as one thing.
If there is an EAR, try adding a file named jboss-deployment-structure.xml to the META-INF folder with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
</jboss-deployment-structure>

You can create an EAR in the following way. Create a my.ear folder in the deployments folder with the following structure:
my.ear
--META-INF
----application.xml
----jboss-deployment-structure.xml
--myWeb1.war
--myWeb2.war
--myEjb1.jar
--myEjb2.jar

Application.xml content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd">
<application>
    <display-name>myApp</display-name>
    <initialize-in-order>true</initialize-in-order>
    <module>
        <java>myEjb1.jar</java>
    </module>

    <module>
        <java>myEjb2.jar</java>
    </module>

    <module>
        <web>
            <web-uri>myWeb1.war</web-uri>
            <context-root>myWeb1</context-root>
        </web>
    </module>
    
    <module>
        <web>
            <web-uri>myWeb2.war</web-uri>
            <context-root>myWeb2</context-root>
        </web>
    </module>
</application>

Libraries that do not contain EJBs (just "carriers" of the desired common classes) can be placed in the my.ear/lib folder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question