Announcement Announcement Module
Collapse
No announcement yet.
jar inside an ear deployment problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • jar inside an ear deployment problem

    Hi,
    I'm encountering the following issue while deploying the application:
    =====================================
    Caused by: org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from class path resource [
    /CalculatorWorkerContext.xml
    ]; nested exception is java.io.FileNotFoundException: class path resource [
    /CalculatorWorkerContext.xml
    ] cannot be opened because it does not exist
    at
    =====================================
    The deployment structure of the app is as follows (.war & jar's inside an .ear):

    .ear
    CalculatorWorker.jar <-- ejb jar
    *.war
    *.jar <-- regular jar

    .etc

    I'm attempting to define the CalculatorWorker app context as a bean inside the CalculatorWorkerContext.xml file like so:

    <bean id="calcAppContext" class="org.springframework.context.support.ClassPa thXmlApplicationContext">
    <constructor-arg>
    <list>
    <value>
    /CalculatorWorkerContext.xml
    </value>
    </list>
    </constructor-arg>
    </bean>

    to which I then refer in code:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ProcessHandler processHandler = (ProcessHandler)SingletonBeanFactoryLocator.
    getInstance().useBeanFactory("calcAppContext").
    getFactory().getBean("processHandler");
    System.out.println("processHandler: " + processHandler);
    processHandler.handleEvent(msg);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Looks like the line doesn't work:

    <value>
    /CalculatorWorkerContext.xml
    </value>

    I've tried classpath:CalculatorWorkerContext.xml and classpath*:CalculatorWorkerContext.xml

    It's located in the root of the CalculatorWorker.jar

    Could someone please point me to what's wrong or missing...

    Thank you,
    Simeon

  • #2
    Originally posted by sleyzerzon
    Hi,
    I'm encountering the following issue while deploying the application:
    =====================================
    Caused by: org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from class path resource [
    /CalculatorWorkerContext.xml
    ]; nested exception is java.io.FileNotFoundException: class path resource [
    /CalculatorWorkerContext.xml
    ] cannot be opened because it does not exist
    at
    =====================================
    The deployment structure of the app is as follows (.war & jar's inside an .ear):

    .ear
    CalculatorWorker.jar <-- ejb jar
    *.war
    *.jar <-- regular jar

    .etc

    I'm attempting to define the CalculatorWorker app context as a bean inside the CalculatorWorkerContext.xml file like so:

    <bean id="calcAppContext" class="org.springframework.context.support.ClassPa thXmlApplicationContext">
    <constructor-arg>
    <list>
    <value>
    /CalculatorWorkerContext.xml
    </value>
    </list>
    </constructor-arg>
    </bean>

    to which I then refer in code:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ProcessHandler processHandler = (ProcessHandler)SingletonBeanFactoryLocator.
    getInstance().useBeanFactory("calcAppContext").
    getFactory().getBean("processHandler");
    System.out.println("processHandler: " + processHandler);
    processHandler.handleEvent(msg);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Looks like the line doesn't work:

    <value>
    /CalculatorWorkerContext.xml
    </value>

    I've tried classpath:CalculatorWorkerContext.xml and classpath*:CalculatorWorkerContext.xml

    It's located in the root of the CalculatorWorker.jar

    Could someone please point me to what's wrong or missing...
    Classloader issues in EARs are tricky to solve. In general, the classloader that loads WAR files can access all JAR files in the /APP-INF/lib directory and the EJB JAR file.

    The JAR files in the /APP-INF/lib directory and the EJB JAR file _cannot_ access resources or classes in the WAR files. So if the /CalculatorWorkerContext.xml file resides in a WAR file it's normal that is cannot be found/loaded.

    If this is not the case we'll need a very detailed understanding of the setup of the EAR and the location of significant resources to solve this problem.

    Comment


    • #3
      I appreciate your looking into this issue for me.
      Here is the detailed setup of the ear and the significant resources:

      Production EAR will consists of a number of jars some of which are ejb jars and a WAR file. Each of this archives have in their classpath (either their root, in case of the jar file, on in their web-inf/classes in case of the war) an XML file representing Spring application context for this deployment module.

      There are also jars residing in the APP-INF/lib of the Weblogic which get preloaded before all the rest of the app and are available to all of the apps deployment units. But I don't think that is the issue.

      We can just disregard all the rest of the jars and wars, and imagine that an ear contains a single jar (an ejb one) called CalculatorWorker.jar. Within this single jar, in its classpath (as I presume to be the jar's root) resides a file called CalculatorWorkerContext.xml.

      Thus, the composition of the CalculatorWorker.jar is the following (packed):

      /-CalculatorWorkerContext.xml
      |
      |-META-INF__
      | |-ejb-jar.xml
      | |-weblogic-ejb-jar.xml
      | |-MANIFEST.MF
      |
      |-com/**/*.class


      In the Manifest.mf file of the CalculatorWorker.jar the classpath is defined as such:

      Class-Path: /lib/antlr-2.7.5.jar /lib/drools-base-2.5-final.jar /lib/d
      rools-core-2.5-final.jar /lib/drools-groovy-2.5-final.jar /lib/drools
      -io-2.5-final.jar /lib/drools-java-2.5-final.jar /lib/drools-jsr94-2.
      5-final.jar /lib/drools-python-2.5-final.jar /lib/drools-smf-2.5-fina
      l.jar /lib/jar.groovy.all-1.0 /lib/janino-2.3.15.jar /lib/jython-2
      0020827-no-oro.jar /lib/xercesImpl-2.6.2.jar /lib/xml-apis-1.0.b2.jar
      /lib/drools-spring-2.5-final.jar /lib/drools-spring-jdk5-2.5-final.j
      ar /lib/drools-decisiontables-2.5-final.jar /lib/commons-jci-SNAPSHOT
      20051110.jar /lib/jdtcore-3.1.0.jar /lib/commons-lang-2.1.jar

      where are of these files reside in the /lib directory of EAR file.

      Please let me know if this is enough information on the archives composition.

      TIA,
      Simeon

      Comment


      • #4
        Where is the ApplicationContext configured that loads the CalculatorWorkerContext.xml file? Is it configured via ContextLoaderListener/Servlet in the web.xml file of a WAR? Or somewhere else?

        Comment


        • #5
          As I mentioned before: there's _no_ WARs, the context is self-configured as a bean inside CalculatorWorkerContext.xml and is being referred to via SingletonBeanFactoryLocator syntax specified in the Spring docs. Like so:
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          <bean id="calcAppContext" class="org.springframework.context.support.ClassPa thXmlApplicationContext">
          <constructor-arg>
          <list>
          <value>
          /CalculatorWorkerContext.xml
          </value>
          </list>
          </constructor-arg>
          </bean>
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          ProcessHandler processHandler = (ProcessHandler)SingletonBeanFactoryLocator.
          getInstance().useBeanFactory("calcAppContext").
          getFactory().getBean("processHandler");
          processHandler.handleEvent(msg);
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          This configuration doesn't work, nor does "classpath: CalculatorWorkerContext.xml" or "classpath*:CalculatorWorkerContext.xml" inside the value tag.

          What worked for me before though is the following setup:

          inside of CalculatorWorker.jar we have our own singleton factory that loads bean factory like so:

          static {
          factory = new XmlBeanFactory(new ClassPathResource(
          FilesConstants.APPLICATION_CONTEXT));
          logger.debug("factory created: " + factory);
          }

          where APPLICATION_CONTEXT is defined in FileConstants as:

          public static final String APPLICATION_CONTEXT = "CalculatorWorkerContext.xml";

          My intent was to eliminate this self-made factory as I discovered that Spring has its own SingletonBeanFactoryLocator serving seemingly the same purpose.

          So, is there a difference in how ClassPa thXmlApplicationContext and ClassPathResource resolve their classpaths? Or is it anything else?

          Thank you,
          Simeon

          Comment


          • #6
            Well, since no one can offer a hand in this presumably 'tricky' classloader issue, looks like it's just another case of advertised but doesn't work... Very unfortunate...

            Comment


            • #7
              Hi,

              I'm still trying to get to the bottom of it and found the following thread describing a similar setup: http://forum.springframework.org/arc...p/t-10990.html
              Not sure if anything changed since the time this was posted...if someone could give me a knowledgeable answer it would be greatly appreciated.
              I still don't understand why the lookup via ClassPathResource (as described in my previous post) works fine, but the one via ClassPathXmlApplicationContext breaks... What I want to achieve is to eliminate the lookups from my application code by having them defined in the context file instead as bean. Given that ClassPathResource works within .jar within .ear setup, is it possible to define a ClassPathResource in the app context, and then use it via this pattern in my code:

              <bean id="calcAppContext" class="org.springframework.???.ClassPathResource">


              .... = (Object)SingletonBeanFactoryLocator.getInstance(). useBeanFactory("calcAppContext").

              Please help...
              Thank you in advance.

              Comment

              Working...
              X