5 Replies Latest reply on Jul 24, 2006 10:55 AM by Adam Warski

    Common classes deployed in a .jar

    Adam Warski Master

      Hello,
      I have a web application (deployed as a .war) and some common classes, which I would like to deploy separately - as a jar. But this does not work - and I suppose ClassLoaders are an issue, or rather my lack of understanding them. However, it's quite weird.
      If I deploy only the .war, then when I try to access some "common" classes I get a ClassNotFoundException.
      If I deploy both the .war and the .jar, then I get a NoClassDefFoundError

      Why is that? How can I achieve my goal?

      Thanks,
      Adam

        • 1. Re: Common classes deployed in a .jar
          Oleg Zhurakousky Newbie

          When you say you deploy both .war and .jar where do you put .jar?

          Oleg

          • 2. Re: Common classes deployed in a .jar
            Adam Warski Master

            Hello,
            I put them both in the deploy directory.

            --
            Cheers,
            Adam

            • 3. Re: Common classes deployed in a .jar
              jaikiran pai Master

              ClassNotFoundException and NoClassDefFoundError are two different things are have different meaning. Post the exception stack trace that you are seeing. When you see the NoClassDefFoundError, it may be a case that even the classes in the .jar file(which you placed in the deploy directory) are found by the classloader, there might be other classes/jars which this class is dependent on and which may not be in the classpath.
              The exception stacktrace will help in identifying the exact reason

              • 4. Re: Common classes deployed in a .jar
                jaikiran pai Master

                Read this

                When you see the NoClassDefFoundError, it may be a case that even the classes in the .jar file


                as

                When you see the NoClassDefFoundError, it may be a case that even though the classes in the .jar file







                • 5. Re: Common classes deployed in a .jar
                  Adam Warski Master

                  So here are the stack traces in all 3 scenarios:

                  1. The .jar is in the WEB-INF/lib directory of the .war - everything works
                  2. The .jar is in the deploy directory, "parallel" to the .war (I though for a while that this was beacuse of deploy order, but I tried changing the names so that the .war goes first and then the .jar, and the other way ruond, but the effect is the same):

                  08:32:58,359 ERROR [[fileAccessServlet]] Servlet.service() for servlet fileAccessServlet threw exception
                  java.lang.NoClassDefFoundError: org/jboss/forge/fileaccess/DownloadsFileAccessMonitor : org/jboss/shotoku/fileaccess/FileAccessMonitor
                   at java.lang.ClassLoader.defineClass(Ljava.lang.String;[BIILjava.security.ProtectionDomain;)Ljava.lang.Class;(Unknown Source)
                   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
                   at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
                   at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
                   at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
                   at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                   at org.jboss.mx.loading.RepositoryClassLoader.findClassLocally(RepositoryClassLoader.java:672)
                   at org.jboss.mx.loading.RepositoryClassLoader.findClass(RepositoryClassLoader.java:652)
                   at java.lang.ClassLoader.loadClass(Ljava.lang.String;Z)Ljava.lang.Class;(Unknown Source)
                   at org.jboss.mx.loading.RepositoryClassLoader.loadClassLocally(RepositoryClassLoader.java:190)
                   at org.jboss.mx.loading.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:131)
                   at org.jboss.mx.loading.LoadMgr3.nextTask(LoadMgr3.java:399)
                   at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:517)
                   at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:405)
                   at java.lang.ClassLoader.loadClass(Ljava.lang.String;Z)Ljava.lang.Class;(Unknown Source)
                   at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:580)
                   at java.lang.ClassLoader.loadClass(Ljava.lang.String;)Ljava.lang.Class;(Unknown Source)
                   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1339)
                   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
                   at java.lang.ClassLoader.loadClassFromNative(Ljava.lang.String;)Ljava.lang.Class;(Unknown Source)
                   at java.lang.Class.forName(Ljava.lang.String;ZLjava.lang.ClassLoader;)Ljava.lang.Class;(Unknown Source)
                   at java.lang.Class.forName(Ljava.lang.String;I)Ljava.lang.Class;(Unknown Source)
                   at org.jboss.shotoku.fileaccess.FileAccessConfiguration.<init>(FileAccessConfiguration.java:35)
                   at org.jboss.shotoku.fileaccess.FileAccessConfigurationWatcher.getConfiguration(FileAccessConfigurationWatcher.java:37)
                   at org.jboss.shotoku.fileaccess.FileAccessConfigurationWatcher.init(FileAccessConfigurationWatcher.java:42)
                   at org.jboss.shotoku.fileaccess.FileAccessConfigurationWatcher.init(FileAccessConfigurationWatcher.java:18)
                  


                  3. The .jar is not present at all, so the classes are simply not there:
                  08:53:16,108 ERROR [FileAccessServlet] Error loading a file access monitor.
                  java.lang.ClassNotFoundException: org.jboss.forge.fileaccess.TempFilesFileAccessMonitor
                   at java.lang.Class.forName(Ljava.lang.String;ZLjava.lang.ClassLoader;)Ljava.lang.Class;(Unknown Source)
                   at java.lang.Class.forName(Ljava.lang.String;I)Ljava.lang.Class;(Unknown Source)
                   at org.jboss.shotoku.fileaccess.FileAccessConfiguration.<init>(FileAccessConfiguration.java:35)
                   at org.jboss.shotoku.fileaccess.FileAccessConfigurationWatcher.getConfiguration(FileAccessConfigurationWatcher.java:37)
                   at org.jboss.shotoku.fileaccess.FileAccessConfigurationWatcher.init(FileAccessConfigurationWatcher.java:42)
                   at org.jboss.shotoku.fileaccess.FileAccessConfigurationWatcher.init(FileAccessConfigurationWatcher.java:18)
                   at org.jboss.shotoku.cache.ShotokuCacheItem.get(ShotokuCacheItem.java:107)
                   at org.jboss.shotoku.fileaccess.FileAccessServlet.doGet(FileAccessServlet.java:57)
                   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
                   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
                   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
                   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
                   at java.lang.Thread.run()V(Unknown Source)
                  


                  --
                  Cheers and thanks for the help,
                  Adam