3 Replies Latest reply on Sep 17, 2009 2:50 AM by jaikiran

    jboss 5 and ClassLoader problem

      I would like to load jboss published in the EAR file jar all xml, but not to load path, Jboss 4 in the original path:the jar's file path = D: / Java/Jboss/server/default/tmp/deploy/tmp29312liveos.ear- contents / liveos.jar, but in jboss 5 :the jar's file path = D: / Java / Jboss / server / default / deploy / liveos.ear / liveos.jar, why not the jar's file path = D: \ Java \ Jboss \ server \ default \ tmp \ vfs-nested.tmp/02804a5d_liveos.jar, such JarFile jarFile = new JarFile (filename); can not find jar

      private void loadConfig() {
      try {
      String osName = System.getProperty("os.name");
      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      String url = loader.getResource(BillConfigCache.class.getName().replace(".", "/") + ".class").toString();
      logger.debug("Current class's filepath : " + url);
      String filename;
      if (osName != null && osName.indexOf("Windows") != -1) {
      logger.debug("Current class begin : " + url.substring(url.indexOf("/")) +"/"+url.substring(url.indexOf(".jar/")+4));
      filename = url.substring(url.indexOf("/") + 1, url.indexOf(".jar/") + 4);
      //filename = url.substring(url.indexOf("/") + 1, url.indexOf("!"));//Jboss 4
      } else {
      filename = url.substring(url.indexOf("/"), url.indexOf(".jar/") + 4);
      //filename = url.substring(url.indexOf("/"), url.indexOf("!"));//Jboss 4
      }
      filename = filename.replace("%20", " ");
      logger.debug("jar's file path = " + filename);

      JarFile jarFile = new JarFile(filename);
      Enumeration entries = jarFile.entries();
      while (entries.hasMoreElements()) {
      JarEntry jarEntry = entries.nextElement();
      String configFile = jarEntry.getName();
      if (jarEntry.getName().toLowerCase().endsWith("xml")) {
      logger.debug("Bill Config File : " + configFile);
      InputStream inputStream = loader.getResourceAsStream(configFile);
      List templateList = createBillTemplate(inputStream);
      cacheBillTemplate(templateList);
      }
      }


      } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw new PAOSBusinessException(e.getMessage(), e);
      }
      }

      Any suggestions?thanks!

        • 1. Re: jboss 5 and ClassLoader problem
          jaikiran

          From what i know, JBossAS5 stopped creating temp jar files for the deployed ones. AS5 now works on the files that are in the deployment folder.

          Going by your code, you seem to be loading all xml files within a jar. If you know the xml file names, then there is a better way to doing this, where you don't have to worry about where the jar files are located.

          By the way, there's specific forum for JBossAS5 questions here http://www.jboss.com/index.html?module=bb&op=viewforum&f=287

          • 2. Re: jboss 5 and ClassLoader problem
            theice

            hi, jaikiran, what's the better way?

            I used "Thread.currentThread().getContextClassLoader().getResource("").getPath()", but there are diffent output in jboss4 and jboss5,why?

            • 3. Re: jboss 5 and ClassLoader problem
              jaikiran

               

              "theice" wrote:
              hi, jaikiran, what's the better way?


              Depends on why you need the "path" of the resource. If you just need the resource, you could do something like:

              this.getClass().getClassLoader().getResource("...");


              Let us know some more details about what you are trying to do.