3 Replies Latest reply on Jul 7, 2006 5:43 PM by Frank Langelage

    getResourceAsStream returns null when invoked from an EJB ja

    Chris Rose Newbie

      My application makes use of a configuration file stored inside a jar that ships in the EAR file. This config file is accessed by way of a classloader.getResourceAsStream(), where the classloader is returned from the Thread.getContextClassloader() method.

      This operation succeeds on WebLogic and WebSphere as expected, but on JBoss 4.0.3SP1, I cannot get anything except a null input stream from this call.

      My application is laid out as:

      app.ear/
       ejb.jar/
       META-INF/MANIFEST.MF: Class-Path: ./config.jar
       com.my.classes.ConfigLoader
       config.jar/
       config.properties


      The loader code is (in brief -- there's a lot of error checking et al that I have removed):
      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      InputStream ins = loader.getResourceAsStream ("/config.properties");
      if (ins == null) {
       System.out("The input stream was null after getResourceAsStream");
      }
      else {
       loadConfig(ins);
      }


      So, what I'm wondering is, of course, why does this not work? I've traced the classloader initialization, and it appears that the config jar is being added to the UCL (here is the trace output from a deployment, up to the point where the beans themselves are configured):
      09:49:05,970 DEBUG [RepositoryClassLoader] Unregistering cl=org.jboss.mx.loading.UnifiedClassLoader3@1d77d9e{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12702app.ear ,addedOrder=30}
      09:49:05,970 DEBUG [UnifiedLoaderRepository3] UnifiedLoaderRepository removed(true) org.jboss.mx.loading.UnifiedClassLoader3@1d77d9e{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12702app.ear ,addedOrder=30}
      09:49:06,004 INFO [EARDeployer] Init J2EE application: file:/opt/md/jboss/server/default/deploy/app.ear
      09:49:06,125 DEBUG [UnifiedClassLoader] New jmx UCL with url file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear
      09:49:06,125 DEBUG [RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.UnifiedLoaderRepository3@10bc49d, cl=org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=0}
      09:49:06,125 DEBUG [RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.UnifiedLoaderRepository3@10bc49d, cl=org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=0}
      09:49:06,125 DEBUG [UnifiedLoaderRepository3] Adding org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=0}
      09:49:06,126 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg:
      09:49:06,509 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.aciworldwide.ecourier.utility
      09:49:06,517 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.aciworldwide.ecourier.auth.jboss
      09:49:06,521 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.aciworldwide.ecourier.auth
      09:49:06,528 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/ejb.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}
      09:49:06,552 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/jrmsadm.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}
      09:49:06,554 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/ecjavautil.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}
      09:49:06,558 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: javax.mail
      09:49:06,569 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: javax.mail.event
      09:49:06,570 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: javax.mail.search
      09:49:06,573 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: javax.mail.internet
      09:49:06,579 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.sun.mail.util
      09:49:06,582 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.sun.mail.smtp
      09:49:06,585 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.sun.mail.iap
      09:49:06,587 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.sun.mail.imap
      09:49:06,594 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.sun.mail.imap.protocol
      09:49:06,599 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.sun.mail.pop3
      09:49:06,601 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.sun.mail.handlers
      09:49:06,602 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/mail.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}
      09:49:06,605 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: javax.activation
      09:49:06,609 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.sun.activation.registries
      09:49:06,610 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: com.sun.activation.viewers
      09:49:06,611 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/activation.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}
      09:49:06,615 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: conf
      09:49:06,615 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: org.opensaml
      09:49:06,642 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: org.opensaml.artifact
      09:49:06,644 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: org.opensaml.provider
      09:49:06,645 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: schemas
      09:49:06,648 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/opensaml-1.1.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}
      09:49:06,814 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/xercesImpl.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}
      09:49:06,833 DEBUG [ClassLoaderUtils] Multiple class loaders found for pkg: org.w3c.dom
      09:49:06,845 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/xml-apis.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}
      09:49:06,880 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/xstream-1.1.2.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}
      09:49:06,881 DEBUG [RepositoryClassLoader] Added url: file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear-contents/config.jar, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@13849df{ url=file:/opt/md/jboss/server/default/tmp/deploy/tmp12704app.ear ,addedOrder=32}