10 Replies Latest reply on Jul 15, 2011 6:59 PM by gonne

    Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib

    gerry.matte

      Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib

       

       

      I've been attempting to port a jbossTests.war web application from Jboss 6 to JBoss 7.

       

      One of my servlets can be used to list all jndi elements.

       

      It stopped working when I implemented the webapp in AS7 with an I/O Error when trying to load the jndi.properties file which defines the jndi environment prior to attempting any lookups.

       

      This file has been deployed to the web application's WEB-INF/lib folder on both JBoss AS6 and on AS7.

       

      On AS7 the properties file isn't found.  However, if I copy the file from WEB-INF/lib to WEB-INF/classes the file is correctly found and the servlet executes without throwing any exceptions.

       

      Has there been a deliberate change in the required location for loading resource files ?  How should I specify in JBoss Tools 3.3-M2 that the properties file must be now deployed to WEB-INF/classes ?

       

      I will post this question here although it may be a JBoss Tools discussion.

       

      The code that loads (or tries to load) the properties file is:

       

       

          /**

           * loadProps locates and loads the properties file identified in

           * JNDI_PROPERTIES_FILE

           *

           * @return Properties the loaded properties which may contain a single

           *   string with key "Error"

           */

          private Properties loadProps() {

             

              // Per page 264 example from O'Reilly "JBoss at Work First Edition October 2005" worked ok on JBoss < 7

              // Note that the properties must be in WEB-INF/classes not in WEB-INF/lib

              Properties p = new Properties();

              ClassLoader loader = Thread.currentThread().getContextClassLoader();

              URL url = loader.getResource(JNDI_PROPERTIES_FILE);

              try {

                  if(url==null) {

                      throw new IOException("URL for File "+JNDI_PROPERTIES_FILE+" not Found");

                      };

                  p.load(url.openStream());

              } catch (IOException e) {

                  p.setProperty("Error","Can't load "+JNDI_PROPERTIES_FILE+": "+e.getMessage());

                  e.printStackTrace();

              }

              return p;

          }

        • 1. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
          gerry.matte

          I forgot to say that the servlet also contains the definition

          public static final String JNDI_PROPERTIES_FILE = "jndi.properties"
          • 2. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
            gerry.matte

            Regardless of whether or not my properties file used to load from WEB-INF/lib, I've now reconfigured the project to now deploy the jndi.properties file to the WEB-INF/classes folder.

             

            Using the jndi.properties noted below, I am now seeing an exception when the webapp attempts to create a JNDI initial context. 

             

            If anyone has any idea what might have changed between AS 6 and AS 7, please let me know.

             

            ====================================================================

            My jndi.properties file is:

            java.naming.provider.url=jnp://localhost:1099

            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

             

            ====================================================================

            The AS 7 startup log is:

            17:12:44,294 INFO  [org.jboss.modules] JBoss Modules version 1.0.0.CR4

            17:12:44,559 INFO  [org.jboss.msc] JBoss MSC version 1.0.0.CR2

            17:12:44,622 INFO  [org.jboss.as] JBoss AS 7.0.0.CR1 "White Rabbit" starting

            17:12:45,511 INFO  [org.jboss.as] creating http management service using network interface (management) port (9990) securePort (-1)

            17:12:45,527 INFO  [org.jboss.as.logging] Removing bootstrap log handlers

            17:12:45,542 INFO  [org.jboss.as.connector.subsystems.datasources] (Controller Boot Thread) Deploying JDBC-compliant driver class org.h2.Driver (version 1.2)

            17:12:45,668 INFO  [org.jboss.as.naming] (Controller Boot Thread) Activating Naming Subsystem

            17:12:45,668 INFO  [org.jboss.as.naming] (MSC service thread 1-5) Starting Naming Service

            17:12:45,684 INFO  [org.jboss.as.osgi] (Controller Boot Thread) Activating OSGi Subsystem

            17:12:45,699 INFO  [org.jboss.as.security] (Controller Boot Thread) Activating Security Subsystem

            17:12:45,699 INFO  [org.jboss.remoting] (MSC service thread 1-16) JBoss Remoting version 3.2.0.Beta2

            17:12:45,715 INFO  [org.xnio] (MSC service thread 1-16) XNIO Version 3.0.0.Beta3

            17:12:45,730 INFO  [org.xnio.nio] (MSC service thread 1-16) XNIO NIO Implementation Version 3.0.0.Beta3

            17:12:46,011 INFO  [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-12) The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\s\java\bin;.;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;c:\s;c:\s\java\bin;c:\s\ant\bin;C:\s\apache-maven-3.0.3\bin;C:\s\seam-3.0.0.Final\forge\bin;C:\Program Files\TortoiseSVN\bin;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\12.0\DLLShared\;C:\s\MySQL\MySQL Server 5.1\bin;C:\s\php;c:\antiword;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\Toshiba\Bluetooth Toshiba Stack\sys\;C:\Program Files (x86)\Toshiba\Bluetooth Toshiba Stack\sys\x64\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Bitvise Tunnelier;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\s\seam-3.0.0.Final\forge\bin;C:\Program Files (x86)\Common Files\Roxio Shared\VHStoDVD\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\13.0\DLLShared\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\QuickTime\QTSystem\

            17:12:46,027 INFO  [org.jboss.as.ee] (Controller Boot Thread) Activating EE subsystem

            17:12:46,042 INFO  [org.jboss.as.jmx.JMXConnectorService] (MSC service thread 1-7) Starting remote JMX connector

            17:12:46,058 INFO  [org.jboss.as.remoting] (MSC service thread 1-11) Listening on /127.0.0.1:9999

            17:12:46,058 WARN  [org.jboss.osgi.framework.internal.URLHandlerPlugin] (MSC service thread 1-15) Unable to set the URLStreamHandlerFactory

            17:12:46,058 WARN  [org.jboss.osgi.framework.internal.URLHandlerPlugin] (MSC service thread 1-15) Unable to set the ContentHandlerFactory

            17:12:46,198 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-13) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080

            17:12:46,261 INFO  [org.jboss.as.connector] (MSC service thread 1-9) Starting JCA Subsystem (JBoss IronJacamar 1.0.0.CR2)

            17:12:46,308 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) Bound data source [java:jboss/datasources/ExampleDS]

            17:12:46,729 INFO  [org.jboss.as.deployment] (MSC service thread 1-2) Started FileSystemDeploymentService for directory C:\s\jboss-7.x\standalone\deployments

            17:12:46,744 INFO  [org.jboss.as.deployment] (DeploymentScanner-threads - 1) Found jbossTests.war in deployment directory. To trigger deployment create a file called jbossTests.war.dodeploy

            17:12:46,744 INFO  [org.jboss.as.deployment] (DeploymentScanner-threads - 1) Found testing.war in deployment directory. To trigger deployment create a file called testing.war.dodeploy

            17:12:46,777 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-12) Starting deployment of "jbossTests.war"

            17:12:47,229 WARNING [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-14) javax.naming.NamingException: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.jbossTests.war:main" from Service Module Loader: javax.naming.NamingException: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.jbossTests.war:main" from Service Module Loader

                at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:58)

                at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:664) [:1.6.0_24]

                at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) [:1.6.0_24]

                at javax.naming.InitialContext.init(InitialContext.java:223) [:1.6.0_24]

                at javax.naming.InitialContext.<init>(InitialContext.java:175) [:1.6.0_24]

                at com.sun.faces.config.WebConfiguration.processJndiEntries(WebConfiguration.java:613) [jsf-impl-2.0.4-b09.jar:2.0.4-b09]

                at com.sun.faces.config.WebConfiguration.<init>(WebConfiguration.java:122) [jsf-impl-2.0.4-b09.jar:2.0.4-b09]

                at com.sun.faces.config.WebConfiguration.getInstance(WebConfiguration.java:182) [jsf-impl-2.0.4-b09.jar:2.0.4-b09]

                at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:163) [jsf-impl-2.0.4-b09.jar:2.0.4-b09]

                at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.0.CR4.jar:7.0.0.CR1]

                at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.0.CR4.jar:7.0.0.CR1]

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

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

                at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

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

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

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

             

            17:12:47,338 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-14) Initializing Mojarra 2.0.4 (FCS b09) for context '/jbossTests'

            17:12:48,274 INFO  [org.jboss.web] (MSC service thread 1-14) registering web context: /jbossTests

            17:12:48,274 INFO  [org.jboss.as] (MSC service thread 1-14) JBoss AS 7.0.0.CR1 "White Rabbit" started in 4198ms - Started 205 of 262 services (57 services are passive or on-demand)

            17:12:48,373 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "jbossTests.war"

            • 3. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
              swd847

              I can't reproduce your problem loading resources from WEB-INF/lib, would you be able to file a jira with a test that reproduces the issue?

               

              The reason why your jndi setup fails to work is because org.jnp.interfaces.NamingContextFactory is not part of AS7. You should be able to use JNDI with no jndi.properties in your app.

              • 4. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
                gerry.matte

                Done.

                The JIRA is at https://issues.jboss.org/browse/AS7-1192

                 

                What is the InitialContextFactory I should be using for JB AS7 ?

                I thought my code was following the J2EE standard for JNDI.

                Can you post some code to show me how to use JNDI to lookup an object in JBoss 7 ?

                 

                Thanks Stuart.

                • 5. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
                  gerry.matte

                  From the jira:

                  David Lloyd resolved AS7-1192.

                  ------------------------------

                   

                      Resolution: Won't Fix

                   

                   

                  No, by spec {{WEB-INF/lib}} is not a class path root.  You can put your file in a JAR in {{WEB-INF/lib}} or directly in {{WEB-INF/classes}} if you want.

                  • 6. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
                    gerry.matte

                    From the jira:

                    David Lloyd resolved AS7-1192.

                    ------------------------------

                     

                        Resolution: Won't Fix

                     

                     

                    No, by spec WEB-INF/lib is not a class path root.  You can put your file in a JAR in WEB-INF/lib or directly in WEB-INF/classes if you want.

                    • 7. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
                      gonne

                      Hi Gerry,

                       

                      do you know which InitialContextFactory to use now?

                       

                      Kind regards,

                      Gonne

                      • 8. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
                        gonne

                        The following InitialContextFactory works for me:

                         

                        java.naming.factory.initial = org.jboss.as.naming.InitialContextFactory

                        • 9. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
                          gerry.matte

                          Hi Gonne.

                          I used javax.naming.InitialContext and was able to list all the expected JEE 6 java contexts and their objects.  I also looked up a DataSource I created and then tested it with an sql query.

                           

                          Do you know of a reason to use the jboss version of InitialContext ?

                          • 10. Re: Classloader Thread.currentThread().getContextClassLoader() no longer inspects WEB-INF/lib
                            gonne

                            There is no difference between specifying no InitialContextFactory (empty environment) and the jboss version, because internally the jboss version is used as default when no one is specified. I have to specify the jboss version because the 3rd party library I use always specifies the InitialContextFactory, so I can not leave it empty.