5 Replies Latest reply on Feb 5, 2013 11:20 AM by penczek

    EAR deployment

    mglowacki

      hi,

       

       

        after I finally have successfully deployed my ejb and web applications as separate JARs and WAR, I want to move them to EAR - so many voices saying it's the best solution...

       

       

      However it does not look like just to create EAR lib, put my working archives and create 2 xml configs...

       

       

      So, my structure is:

       

       

      /App.EAR

        /EntityBeans.jar

        /lib

      /MessageDrivenBeans.jar

      /META-INF

      /MyApp.war

      /SessionBeans.jar

       

       

      application xml:

       

       

       

       

      <?xml version="1.0" encoding="UTF-8"?>

      <application xmlns="http://java.sun.com/xml/ns/javaee"

                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"

                   version="5">

       

       

          <display-name>App</display-name>   

       

       

          <module>           

              <ejb>EntityBeans.jar</ejb>

              <ejb>SessionBeans.jar</ejb>

              <ejb>MessageDrivenBeans.jar</ejb>

              <web>

                  <web-uri>MyApp.war</web-uri>

                  <context-root>/MyApp</context-root>

              </web>

          </module>

       

       

      </application>

       

       

       

       

      jboss-deployment-structure.xml:

       

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

                <ear-subdeployments-isolated>false</ear-subdeployments-isolated>

                <deployment>

                          <dependencies>

                                    <module name="javax.faces.api" slot="1.2" export="true" />

                                    <module name="com.sun.jsf-impl" slot="1.2" export="true" />

                                    <module name="org.apache.log4j" export="true"/>

                                    <module name="org.infinispan" />

                                    <module name="org.slf4j" />

                                    <module name="org.javassist" />

                                    <module name="org.dom4j" />

                                    <module name="org.hibernate" export="true"/>

                          </dependencies>

                </deployment>

                <sub-deployment name="EntityBeans.jar"/>

                <sub-deployment name="SessionBeans.jar"/>

                <sub-deployment name="MessageDrivenBeans.jar"/>

                <sub-deployment name="MyApp.war">

                          <exclusions>

                                    <module name="javax.faces.api" slot="main" />

                                    <module name="com.sun.jsf-impl" slot="main" />

                          </exclusions>

                          <dependencies>

                                    <module name="javax.faces.api" slot="1.2" />

                                    <module name="com.sun.jsf-impl" slot="1.2" />

                                    <module name="org.dom4j" />

                                    <module name="org.infinispan" />

                                    <module name="org.slf4j" />

                          </dependencies>

                </sub-deployment>

      </jboss-deployment-structure>

       

       

       

       

       

       

       

       

      First problem came with EntityBeans.jar - I had to create ejb-jar.xml in order to this deployment be visible. But this one is solved.

       

       

      Second is once again persistence... I have moved persistence.xml from EntityBeans.jar/META-INF to META-INF of ear - now I get

       

       

      java.lang.RuntimeException: Missing annotation index to scan entity classes

       

       

      But as I saw, it is a bug and should be fixed in 7.0.2. However my war classes are not able to find persistence unit in jndi again... When I deploy as separate, I had always after start of JBoss redeploy my war file, and then it saw persistence unit. Here I cannot do it (not mention it is hard-way). What is the problem now? I keep getting:

       

       

      EntityManagerFactory not found in JNDI : java:jboss/MyPUManagerFactory or

      javax.naming.NameNotFoundException: Name 'MyPUManagerFactory' not found in context '' - what is totally mess because in corresponding class I look for it this way:

       

       

      (javax.persistence.EntityManagerFactory) new InitialContext().lookup("java:jboss/MyPUManagerFactory");

       

       

      and part of my persistence.xml looks like this:

       

       

      <property name="jboss.entity.manager.jndi.name" value="java:jboss/MyPU"/>

      <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/MyPUManagerFactory" />

       

       

      And again - it worked in separate deployment.

       

       

      3rd problem is classloading. I am very surprised that I have to redefine dependencies for my WAR (please see xml above) - I thought that all defined in deploment are visible for sub-deployments. And that my WAR file is not seeing libraries located under it's WEB-INF/lib folder - I had to copy them into EAR's lib dir.

       

       

      Could anybody help/advise on above? Thanks.

       

       

      Michal

        • 1. Re: EAR deployment
          prasad.deshpande

          Firstly, Entity beans are not as such EJB that they we're in 2.1, so you don't need to make them as ejb in your application.xml (and from jboss-deployment-structure.xml). You can safely move that jar to lib directory of your ear (You wouldn't even need to create ejb-jar in that case). When you move entitybeans.jar to lib, you can move your persistence.xml to entitybeans.jar/META-INF, your PU should then be available to your WAR and to your ejb's.

           

          After doing this, try revisiting jboss-deployment-structure.xml for your WAR dependencies.

          1 of 1 people found this helpful
          • 2. Re: EAR deployment
            mglowacki

            I just found that persistence.xml cannot be in EAR/META-INF (https://docs.jboss.org/author/display/AS7/Developer+Guide#DeveloperGuide-Deployment) - but it does not help me at all :/

            • 3. Re: EAR deployment
              mglowacki

              The problem is that I think WAR is deploying too fast now in JBoss 7 15 seconds to start and deploy whole EAR. I need to redeploy EAR in order to entity manager factory be visible. I have entity manager factory initialization in static block, also some @Startup annotations in classes accessing database (loading some data into cache) and this is a problem for me.

               

              However, on the other side, strange is the error:

               

              Name 'MyPUManagerFactory' not found in context ''

               

              And I look for "java:jboss/MyPUManagerFactory", why the context is empty then?

              • 4. Re: EAR deployment
                intr13

                exists a solution for this problem?

                 

                my structure:

                *ear

                ** libs

                ** ejb

                *** META-INF

                **** persistence.xml

                *** ejb classes

                ** war

                *** WEB-INF

                **** web.xml (links to ejb)

                 

                my log (probability of error ~90%):

                16:01:05,859 INFO  [org.jboss.jpa] (MSC service thread 1-4) stopping Persistence Unit Service 'test-rest.ear/test-rest-ejb.jar#my-entity-manager'

                16:01:05,905 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) Stopped deployment test-rest-ejb.jar in 59ms

                16:01:05,905 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) Stopped deployment test-rest.war in 60ms

                16:01:05,916 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) Stopped deployment test-rest.ear in 71ms

                16:01:05,917 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "test-rest.ear"

                16:01:06,370 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) Starting deployment of "test-rest.war"

                16:01:06,370 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) Starting deployment of "test-rest-ejb.jar"

                16:01:06,379 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry test-rest-api-trunk.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,379 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry jaxb-api-2.2.4.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,379 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry jaxrs-api-2.2.3.GA.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,379 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry activation-1.1.1.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,379 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry stax-api-1.0-2.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,379 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry resteasy-jaxrs-2.2.3.GA.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,379 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry scannotation-1.0.3.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,380 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry javassist-3.12.1.GA.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,380 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry jsr250-api-1.0.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,380 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry jcip-annotations-1.0.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,380 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry commons-logging-1.1.1.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,380 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry commons-codec-1.5.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,381 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry resteasy-jaxb-provider-2.2.3.GA.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,381 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry jaxb-impl-2.2.4.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,381 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry sjsxp-1.0.1.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,381 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry commons-collections-3.2.1.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,381 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry commons-lang-2.6.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,381 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry commons-io-2.0.1.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,381 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry velocity-1.7.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,381 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry velocity-tools-2.0.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,382 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-2) Class Path entry some-rs-api-1.0.0.jar in "/content/test-rest.ear/test-rest-ejb.jar"  does not point to a valid jar for a Class-Path reference.

                16:01:06,390 INFO  [org.jboss.jpa] (MSC service thread 1-2) read persistence.xml for my-entity-manager

                16:01:06,391 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) added javax.persistence.api, javaee.api, org.jboss.as.jpa, org.javassist dependencies to test-rest.ear

                16:01:06,391 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) added (default provider) org.hibernate dependency to application deployment (since 1 PU(s) didn't specify jboss.as.jpa.providerModule)

                16:01:06,392 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) added org.hibernate dependency to application deployment

                16:01:06,392 INFO  [org.jboss.as.jpa] (MSC service thread 1-4) added javax.persistence.api, javaee.api, org.jboss.as.jpa, org.javassist dependencies to test-rest.war

                16:01:06,392 INFO  [org.jboss.as.jpa] (MSC service thread 1-1) added javax.persistence.api, javaee.api, org.jboss.as.jpa, org.javassist dependencies to test-rest-ejb.jar

                16:01:06,392 INFO  [org.jboss.as.jpa] (MSC service thread 1-1) added (default provider) org.hibernate dependency to application deployment (since 1 PU(s) didn't specify jboss.as.jpa.providerModule)

                16:01:06,393 INFO  [org.jboss.as.jpa] (MSC service thread 1-1) added org.hibernate dependency to application deployment

                16:01:06,432 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named sms-gate-service in deployment unit subdeployment "test-rest-ejb.jar" of deployment "test-rest.ear" are as follows:

                 

                 

                          java:global/test-rest/test-rest-ejb/sms-gate-service!my.company.test.rest.service.ISmsService

                          java:app/test-rest-ejb/sms-gate-service!my.company.test.rest.service.ISmsService

                          java:module/sms-gate-service!my.company.test.rest.service.ISmsService

                          java:global/test-rest/test-rest-ejb/sms-gate-service

                          java:app/test-rest-ejb/sms-gate-service

                          java:module/sms-gate-service

                 

                 

                16:01:06,432 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named test/user-facade in deployment unit subdeployment "test-rest-ejb.jar" of deployment "test-rest.ear" are as follows:

                 

                 

                          java:global/test-rest/test-rest-ejb/test/user-facade!my.company.test.rest.test.facade.IuserFacade

                          java:app/test-rest-ejb/test/user-facade!my.company.test.rest.test.facade.IuserFacade

                          java:module/test/user-facade!my.company.test.rest.test.facade.IuserFacade

                          java:global/test-rest/test-rest-ejb/test/user-facade

                          java:app/test-rest-ejb/test/user-facade

                          java:module/test/user-facade

                 

                 

                16:01:06,436 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named velocity-template-service in deployment unit subdeployment "test-rest-ejb.jar" of deployment "test-rest.ear" are as follows:

                 

                 

                          java:global/test-rest/test-rest-ejb/velocity-template-service!my.company.test.rest.service.ITemplateService

                          java:app/test-rest-ejb/velocity-template-service!my.company.test.rest.service.ITemplateService

                          java:module/velocity-template-service!my.company.test.rest.service.ITemplateService

                          java:global/test-rest/test-rest-ejb/velocity-template-service

                          java:app/test-rest-ejb/velocity-template-service

                          java:module/velocity-template-service

                 

                 

                16:01:06,436 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named test/user-service in deployment unit subdeployment "test-rest-ejb.jar" of deployment "test-rest.ear" are as follows:

                 

                 

                          java:global/test-rest/test-rest-ejb/test/user-service!my.company.test.rest.test.service.IuserService

                          java:app/test-rest-ejb/test/user-service!my.company.test.rest.test.service.IuserService

                          java:module/test/user-service!my.company.test.rest.test.service.IuserService

                          java:global/test-rest/test-rest-ejb/test/user-service

                          java:app/test-rest-ejb/test/user-service

                          java:module/test/user-service

                 

                 

                16:01:06,437 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named test/user-dao in deployment unit subdeployment "test-rest-ejb.jar" of deployment "test-rest.ear" are as follows:

                 

                 

                          java:global/test-rest/test-rest-ejb/test/user-dao!my.company.test.rest.test.dao.IuserDao

                          java:app/test-rest-ejb/test/user-dao!my.company.test.rest.test.dao.IuserDao

                          java:module/test/user-dao!my.company.test.rest.test.dao.IuserDao

                          java:global/test-rest/test-rest-ejb/test/user-dao

                          java:app/test-rest-ejb/test/user-dao

                          java:module/test/user-dao

                 

                 

                16:01:06,545 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/test-rest]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap: java.lang.RuntimeException: javax.naming.NameNotFoundException: java:app/test-rest-ejb/test/user-facade

                          at org.jboss.resteasy.plugins.server.resourcefactory.JndiResourceFactory.getScannableClass(JndiResourceFactory.java:62) [resteasy-jaxrs-2.2.1.GA.jar:]

                          at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:95) [resteasy-jaxrs-2.2.1.GA.jar:]

                          at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:83) [resteasy-jaxrs-2.2.1.GA.jar:]

                          at org.jboss.resteasy.core.ResourceMethodRegistry.addJndiResource(ResourceMethodRegistry.java:57) [resteasy-jaxrs-2.2.1.GA.jar:]

                          at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:350) [resteasy-jaxrs-2.2.1.GA.jar:]

                          at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:225) [resteasy-jaxrs-2.2.1.GA.jar:]

                          at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28) [resteasy-jaxrs-2.2.1.GA.jar:]

                          at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                          at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                          at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]

                          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)

                          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)

                          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]

                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]

                          at java.lang.Thread.run(Thread.java:662) [:1.6.0_26]

                Caused by: javax.naming.NameNotFoundException: java:app/test-rest-ejb/test/user-facade

                          at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:55)

                          at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:209)

                          at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_26]

                          at org.jboss.resteasy.plugins.server.resourcefactory.JndiResourceFactory.getScannableClass(JndiResourceFactory.java:57) [resteasy-jaxrs-2.2.1.GA.jar:]

                          ... 14 more

                 

                 

                16:01:06,557 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-3) Error listenerStart

                16:01:06,557 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-3) Context [/test-rest] startup failed due to previous errors

                16:01:06,559 INFO  [org.jboss.web] (MSC service thread 1-3) registering web context: /test-rest

                16:01:06,563 INFO  [org.jboss.jpa] (MSC service thread 1-4) starting Persistence Unit Service 'test-rest.ear/test-rest-ejb.jar#my-entity-manager'

                16:01:06,570 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-4) HHH00204:Processing PersistenceUnitInfo [

                          name: my-entity-manager

                          ...]

                16:01:06,576 INFO  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-4) HHH00130:Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider

                16:01:06,839 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-4) HHH00400:Using dialect: org.hibernate.dialect.HSQLDialect

                16:01:06,849 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-4) HHH00424:Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

                16:01:06,850 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-4) HHH00268:Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory

                16:01:06,850 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-4) HHH00397:Using ASTQueryTranslatorFactory

                16:01:06,873 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Replaced deployment "test-rest.ear" with deployment "test-rest.ear"

                • 5. Re: EAR deployment
                  penczek

                  This error was happening with me on an intermitent way (sometimes it worked, sometimes got error), when WAR was deployed before the referred EJB.

                  I've tried everything about module dependecies, to force WAR to be deployed after EJB.

                  I've found the solution here: use <initialize-in-order>true</initialize-in-order> in the the EAR's application.xml deployment descriptor.

                  That way the WAR waits until EJB is completely deployed, and then Resteasy can successfully scans the JNDIs.