6 Replies Latest reply on Aug 18, 2003 12:26 PM by programmer

    Which jars do I need in the Classpath?

    programmer Newbie

      Hi,
      I am new to EJB and am following the book Java for the Web with Servlets, JSP and EJB by Budi Kurniawan.

      I have created a bean, its home and remote interfaces and an xml file, put them in a jar and successfully deployed them.

      My environment is Windows 2000, Java 1.4 and JBoss 4.0. The following are in my classpath:
      jboss-j2ee.jar
      jboss-all-client.jar
      jnp-client.jar
      among other jars.

      Now when I run the client application, I get the following error:
      java.lang.NoClassDefFoundError: org/apache/log4j/Category
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
      at java.lang.Class.getConstructor0(Class.java:1762)
      at java.lang.Class.newInstance0(Class.java:276)
      at java.lang.Class.newInstance(Class.java:259)
      at org.jboss.logging.Logger.getDelegatePlugin(Logger.java:312)
      at org.jboss.logging.Logger.(Logger.java:78)
      at org.jboss.logging.Logger.getLogger(Logger.java:291)
      at org.jnp.interfaces.NamingContext.(NamingContext.java:103)
      at org.jnp.interfaces.NamingContextFactory.getInitialContext(NamingContextFactory.java:41)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
      at javax.naming.InitialContext.init(InitialContext.java:219)
      at javax.naming.InitialContext.(InitialContext.java:195)
      at BeanClient.main(BeanClient.java:17)

      BeanClient is my client class.

      What am I doing wrong?

      Thanks in advance.

        • 1. Re: Which jars do I need in the Classpath?
          Jon Barnett Master

          Most times, all you will need is the jbossall-client.jar. Many of the other classes are separate bundlings of the classes that already appear in jbossall-client.jar. In your instance, I would drop the other JARs you have there as they are already contained in jbossall-client.jar.

          On occassions, you may need additional JARs depending on local issues. You have such an instance here. You will need to include log4j.jar - it is also in the client directory of the distribution.

          • 2. Re: Which jars do I need in the Classpath?
            programmer Newbie

            Hi Jonlee,
            Thanks for the reply.
            Something's still wrong though.

            After I added log4j.jar, I got two more class not found exceptions and I fixed those by adding
            lib\jboss-system.jar (for ServiceMBeanSupport class) and
            lib\jboss-remorting.jar (for ClientInterceptor class).

            Question: Was this right? Are there files in the client folder in which the above classes can be found?

            But now I have started getting this error:
            FATAL [main] (ClientServiceMBeanSupport.java:76) - Could not set up mbean server or mbeans in client
            javax.management.ReflectionException: The MBean class could not be loaded by the default loader repository
            at com.sun.jdmk.MBeanInstantiatorImpl.findClassWithDefaultLoaderRepository(MBeanInstantiator
            .java:64)
            .
            .
            .
            at BeanClient.main(BeanClient.java:21)
            javax.naming.CommunicationException [Root exception is java.io.InvalidObjectException: Problem setti
            ng up mbean server or mbeans in client: javax.management.ReflectionException: The MBean class could
            not be loaded by the default loader repository]

            I have no idea what that means and how to solve it.

            At this point my entire classpath looks like this:
            .
            C:\j2sdkee1.4\lib\j2ee.jar
            E:\webMethods\Developer4\lib\client.jar
            E:\Tomcat 4.1\common\lib\mysql-connector-java-3.1.0-alpha-bin.jar
            E:\Tomcat 4.1\common\lib\servlet.jar
            E:\oracle\ora92\jdbc\lib\ojdbc14.jar
            E:\Program Files\Altova\xmlspy\XMLSpyInterface.jar
            E:\jboss-4.0.0DR2\client\jboss-j2ee.jar
            E:\jboss-4.0.0DR2\client\jboss-all-client.jar
            E:\jboss-4.0.0DR2\client\jnp-client.jar
            E:\jboss-4.0.0DR2\client\log4j.jar
            E:\jboss-4.0.0DR2\client\jboss-system-client.jar
            E:\jboss-4.0.0DR2\lib\jboss-system.jar
            E:\jboss-4.0.0DR2\lib\jboss-remoting.jar

            Thanks in advance.

            • 3. Re: Which jars do I need in the Classpath?
              Jon Barnett Master

              I'd check your naming - I think it should be jbossall-client.jar, not jboss-all-client.jar. I think this is the reason you are having the class problems because the primary library is actually not being loaded as it is not included in the classpath. Drop all your JBoss classes (jboss-j2ee.jar classes are actually in jbossall-client.jar) and add just jbossall-client.jar (unless 4.0.x has changed from 3.2.x and has really named the class jboss-all-client.jar) and the log4j.jar. See how that goes after this.

              • 4. Re: Which jars do I need in the Classpath?
                programmer Newbie

                It is named jboss-all-client.jar.
                I did as you said retaining only two jboss jars, jboss-all-client and log4j.
                I started getting
                NoClassDefFoundError: org/jboss/system/ServiceMBeanSupport

                So I added
                E:\jboss-4.0.0DR2\lib\jboss-system.jar

                after which I got the error
                java.lang.NoClassDefFoundError: Lorg/jboss/remoting/ClientInterceptor;

                So I added
                E:\jboss-4.0.0DR2\lib\jboss-remoting.jar
                which caused the error
                FATAL [main] (ClientServiceMBeanSupport.java:76) - Could not set up mbean server or mbeans in client

                Here's a part of the source:
                public class BeanClient
                {
                public static void main(String[] args)
                {
                Properties props = new Properties();
                props.put(Context.INITIAL_CONTEXT_FACTORY,
                "org.jnp.interfaces.NamingContextFactory");
                props.put(Context.PROVIDER_URL, "localhost:1099");

                try
                {
                // get an initial context
                InitialContext jndiContext = new InitialContext(props);
                System.out.println("Got context");

                // get a reference to the bean
                Object ref = jndiContext.lookup("Adder");

                I get the error at the last line. It gets the context and prints out the "Got context" message.

                • 5. Re: Which jars do I need in the Classpath?
                  Jon Barnett Master

                  It seems like you have managed to somehow invoke an AOP-like operation since for some reason it is expecting local MBeans and remoting - this is not the behaviour expected and one you would not get from 3.2.x. I'm not that familiar with these new features since JBoss 4.0 is still a Developer Release.

                  I have noticed you are missing a necessary initial property:
                  java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

                  e.g. props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                  You might want to try that first to see if this solves part of the problem and gets your client working like a standard Java class. Otherwise you are going to need to get help from someone working with 4.0.x.

                  • 6. Re: Which jars do I need in the Classpath?
                    programmer Newbie

                    Something about release 4.0 is different.
                    I uninstalled it and installed 3.2.2RC2.
                    I then put only those jar files that you recommended in the classpath.
                    My program ran without a problem!