4 Replies Latest reply on Sep 12, 2014 11:05 AM by Philippe Marschall

    Access classpath resource from other EAR in the same deployment

    Wolfgang Vullhorst Newbie

      Hi,

       

        after hours of reading the documentation I'm still stuck. Here is my problem:

       

      My deployment consists of 2 EAR files:

       

      - connectors-1.0-SNAPSHOT.ear

      --- META-INF/jboss-deployment-structure.xml

      --- connectors-1.0-SNAPSHOT.jar

      ----- my/app/spring/applicationContext.xml

      --- ...

       

       

      - server.ear

      --- META-INF/jboss-deployment-structure.xml

      --- server-impl.jar

      --- ...

       

      The Server implementation (server-impl.jar) uses Spring with file based configuration (applicationContext.xml). One of the configuration files is located in the connectors.jar within the connectors.ear.

      Following the documentation of modules and dependencies my deployment-structure files now look like this:

       

      connectors-1.0-SNAPSHOT.ear/META-INF/jboss-deployment-structure.xml:

      <jboss-deployment-structure>

          <module name="deployment.connectors" slot="main">

              <resources>

                  <resource-root path="connectors-1.0-SNAPSHOT.jar"/>

              </resources>

          </module>

      </jboss-deployment-structure>

       

      server.ear/META-INF/jboss-deployment-structure.xml:

      <jboss-deployment-structure>

          <deployment>

              <dependencies>

                  <module name="deployment.connectors"/>

              </dependencies>

          </deployment>

      </jboss-deployment-structure>

       

      When deploying the ear files, there are no error messages about undefined modules, so the dependency from server.ear to "deployment.connectors" appears to be valid.

      But: When Spring tries to access an applicationContext located in the connectors-1.0-SNAPSHOT.jar, it fails with

       

      2014-09-08 14:28:47,056 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "server.ear")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.subunit.\"server.ear\".\"server-impl.jar\".component.StartupListener.START" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"server.ear\".\"server.jar\".component.StartupListener.START: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance

          Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance

          Caused by: javax.ejb.EJBException: JBAS014580: Unexpected Error

          Caused by: java.lang.ExceptionInInitializerError

          Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SERVER' defined in URL [file:/D:/Programme/Wildfly/configuration/contexts.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [my/app/spring/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [my/app/spring/applicationContext.xml] cannot be opened because it does not exist

          Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [my/app/spring/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [my/app/spring/applicationContext.xml] cannot be opened because it does not exist

          Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [my/app/spring/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [my/app/spring/applicationContext.xml] cannot be opened because it does not exist

          Caused by: java.io.FileNotFoundException: class path resource [my/app/spring/applicationContext.xml] cannot be opened because it does not exist"}}

       

      Any ideas?

       

      Thank you very much in advance for your help,

        Wolfgang

        • 1. Re: Access classpath resource from other EAR in the same deployment
          Tomaz Cerar Master

          All you need is to tell your server.ear to have dependency to connector, so your server.ear/META-INF/jboss-deployment-structure.xml should look something like this:

           

          <jboss-deployment-structure>

              <deployment>

                  <dependencies>

                          <module name="deployment.connectors-1.0-SNAPSHOT.ear"/> <!-- this is name of the deployment you see in log while doing deployment-->

                  </dependencies>

              </deployment>

          </jboss-deployment-structure>

          but! that will only work properly if connectors ear connectors defined as lib and not as deployment module like ejb-jar etc.

          for that, name of dependency needed would be deployment.connectors-1.0-SNAPSHOT.connectors-1.0-SNAPSHOT.jar

           

          i would recommend you to modify your maven config to not include versions in ear modules, you can do that by configuring ear plugin with this option

           

          <configuration>
          ...
            <fileNameMapping>no-version</fileNameMapping>
          ...
            </configuration>

          also configuring finalName for artifact would help you produce ear without version.

          1 of 1 people found this helpful
          • 2. Re: Access classpath resource from other EAR in the same deployment
            Wolfgang Vullhorst Newbie

            Hi Tomaz,

             

              thank you for your reply.

            I'm still stuck as I do completely understand the dependency structures here. I removed the version information from the artifacts now, but the rest is not completely clear to me.

            Maybe you can help me out:

            I removed the EJB definition ("<ejb>" in application.xml) from the connectors.ear. Where in the EAR file do I put my connectors.jar, directly into the root folder of the EAR archive or in a folder "lib"?

             

            Do I need a deployment-structure in connectors.ear to define the module? If yes, how do I have to define it? A module definition "deployment.connectors.ear" fails during deployment (DuplicateServiceException).

             

            How exactly do I refer to the module definition then? Regardless of the module name defined in connectors.ear, the server log only shows

             

            2014-09-11 14:34:18,787 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "connectors.ear" (runtime-name: "connectors.ear")

            2014-09-11 14:34:21,972 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "connectors.ear" (runtime-name : "connectors.ear")

             

            Best regards,

              Wolfgang

            • 3. Re: Access classpath resource from other EAR in the same deployment
              Tomaz Cerar Master

              No you connectors.ear doesn't need jboss-deployment-structure.xml

              that is why it probably complains, as you have module "deployment.connectors.ear" defined in it and it fails.

               

              you only need j-d-s.xml in deployment that need to depend to something external.

               

              in short you would probably just need dependency on "deployment.connectors.ear" and that is about it.

              but be warned that this way you will bring in all classes from that EAR, but there is a way to filter it.

               

              lets just first make it work with all classes

              • 4. Re: Re: Access classpath resource from other EAR in the same deployment
                Philippe Marschall Expert

                Tomaz Cerar wrote:

                 


                 

                i would recommend you to modify your maven config to not include versions in ear modules, you can do that by configuring ear plugin with this option

                 

                <configuration>
                ...
                  <fileNameMapping>no-version</fileNameMapping>
                ...
                  </configuration>

                also configuring finalName for artifact would help you produce ear without version.

                There is actually a no-version-for-ejb file name mapping that omits the version only for EJB-JARs and keeps the version for library JARs.