4 Replies Latest reply on Jun 11, 2009 6:24 AM by James Glenn

    cannot load classes located in WEB-INF/lib

    James Glenn Newbie

      I am not sure if this is a JBoss or Railo thing, I'm leaning toward JBoss, but here's the basic situation.

      I have an EAR deployment with a WAR inside the EAR, when I start up JBoss with some custom JAR files in the WEB-INF/lib folder of the WAR, it starts up fine. JBoss uses the files as it should to create classes that are created at startup (servlets defined in web.xml in WEB-INF of the WAR)

      However, if I attempt to load those classes from within a Railo page with createObject() Railo throws an error that it cannot see them.

      If I place the JAR files in the lib folder for the EAR, Railo can see them fine and use them with createObjstarect()

      So, is Railo not able to see classes in WEB-INF/lib after the startup? Or is this a JBoss issue?

      The reason I need to do this is that I want some WARs to have the libraries and some not.

      My actual issue is that I want to have WEB-INF/lib/customjars1, WEB-INF/lib/customjars2, etc I want a /lib/hibernate folder, etc I have too many JARs and I want to keep them organized.

      I can't figure out how to get JBoss to look in sub folders of WEB-INF/lib for folders in each WAR.

      In JBoss in the jboss-service.xml I can specify additional classpaths, which works, but the problem is that you then have to modify the jboss-service.xml file and add a path for each WAR that you add. I want the WARs to contain all of the needed information without having to modify JBoss for each one.

      I can work around this by putting the JARs in the lib folder for the EAR, but like I said, I don't want all the WARs to have them and there are conflicts in some.

      So, what's going on here? How can I get Railo to see the classes in WEB-INF/lib at runtime?

      Thanks!!

        • 1. Re: cannot load classes located in WEB-INF/lib
          James Glenn Newbie

          I thought I'd add... I'd like to be able to specify in jboss-service.xml in the server/default/conf folder to look in an additional folder in each WEB-INF for libs if it existed.

          So to be able to add some way to reference WEB-INF/lib/extra in the same way as:



          So something like:



          Of course, this looks in the server lib, not the WAR lib. So, what kind of modification could I make here to tell JBoss to load JARs from the WEB-INF/lib/extra (or WEB-INF/extra/lib1) folder in each WAR during startup?

          Or is there a better way to do this?

          My main issue is that I need the JARs available at startup, but also need them available at runtime, but not located in the lib folder of the EAR, but per WAR. If I put them in WEB-INF/lib they do load at startup, but cannot be accessed at runtime as they can when loaded in the EAR/lib

          Thanks!

          • 2. Re: cannot load classes located in WEB-INF/lib
            James Glenn Newbie

            Oops, code didn't show up.

            to be able to add some way to reference WEB-INF/lib/extra in the same way as:

             <classpath codebase="${jboss.server.lib.url:lib}" archives="*"/>
            

            So something like:

            <classpath codebase="${jboss.server.lib.url:lib}/extra" archives="*"/>


            Of course, this looks in the server lib, not the WAR lib. So, what kind of modification could I make here to tell JBoss to load JARs from the WEB-INF/lib/extra (or WEB-INF/extra/lib1) folder in each WAR during startup?

            • 3. Re: cannot load classes located in WEB-INF/lib
              James Glenn Newbie

              I should also add that when I use just a WAR for deployment, without it being inside an EAR, this works just fine and the library loads as needed at runtime from WEB-INF/lib, so this is only an issue when putting the WAR inside and EAR.

              • 4. Re: cannot load classes located in WEB-INF/lib
                James Glenn Newbie

                I should add that I tried the code below with my JARs in WEB-INF/lib
                and am receiving the error below. With the JARs in the EAR file I
                don't have to do the updateJar, I can just use the code as is without
                the two tags and it works. I'm not sure if this is a
                dependency thing or what, I'm a little baffled. I just need to get
                ahold of the Spring application context from within Railo, which I can
                do with the JAR in the EAR/lib but not this way.

                <cfadmin action="updateJar"
                 type="web"
                 password="testtest"
                 jar="/work/jboss/jboss-4.2.3.GA/server/default/deploy/
                railo.ear/railo1.war/WEB-INF/lib/spring.jar">
                
                 <cfset var utils = createObject("java",
                "org.springframework.web.context.support.WebApplicationContextUtils",
                "/work/jboss/jboss-4.2.3.GA/server/default/deploy/railo.ear/railo1.war/
                WEB-INF/lib/spring.jar") />
                
                 <cfset var context = getPageContext().getServletContext() />
                
                 <cfset variables.applicationContext = utils.getWebApplicationContext
                (context)>
                
                <cfadmin action="removeJar"
                 type="web"
                 password="testtest"
                 jar="/work/jboss/jboss-4.2.3.GA/server/default/deploy/
                railo.ear/railo1.war/WEB-INF/lib/spring-web-2.0.4.jar">


                When I do this I get the following error:

                Root context attribute is not of type WebApplicationContext:
                org.springframework.web.context.support.XmlWebApplicationContext@1ff48d8:
                display name [Root WebApplicationContext]; startup date [Thu Jun 11
                03:06:42 PDT 2009]; root of context hierarchy
                at
                org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext
                (WebApplicationContextUtils.java:66):66
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):-2
                at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source):-1
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source):-1
                at java.lang.reflect.Method.invoke(Unknown Source):-1
                at railo.runtime.reflection.pairs.MethodInstance.invoke
                (MethodInstance.java:37):37
                at railo.runtime.java.JavaObject.call(JavaObject.java:241):241
                at railo.runtime.java.JavaObject.call(JavaObject.java:260):260
                at railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues
                (VariableUtilImpl.java:617):617