5 Replies Latest reply on Feb 14, 2003 5:28 PM by Peter Doornbosch

    Deployed OK but application client won't run

    Andrew Newbie

      I had a go at a simple HelloWorld tutorial. I got the bean deployed in JBoss-3.0.4 fine but I've been having problems with the application client.
      It compiles ok but I can't get it to run. Here is the error message:

      Exception in thread "main"java.lang.NoClassDefFoundError: HelloWorldClient (wrong name: com/mastertech/sample/HelloWorldClient)
      at java.lang.ClassLoader.defineClass0(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
      .....

      The NoClassDefFoundError sugests there is something missing from the class path.

      Here is my current class path:
      C:\j2sdkee1.3.1\lib\j2ee.jar;
      C:\jboss-3.0.4\client\log4j.jar;
      C:\jboss-3.0.4\client\jboss-common-client.jar;
      C:\jboss-3.0.4\client\jboss-system-client.jar;
      C:\jboss-3.0.4\client\jnp-client.jar;
      C:\jboss-3.0.4\client\jboss-client.jar;
      C:\jboss-3.0.4\client\jbosssx-client.jar;
      C:\jboss-3.0.4\client\jboss-j2ee.jar;
      C:\jboss-3.0.4\client\jbossall-client.jar
      C:\Andrew\BuildExamplesUsingAnt\HelloWorld\dist\lib\HelloWorld.jar

      As you can see I have added a few extra jar files just in case, but to no avail.

      Any ideas?

      Andrew

        • 1. Re: Deployed OK but application client won't run
          Adrian Brock Master

          Try

          jar -tf HelloWorld.jar and compare the output with
          the name in the error and the package you defined
          in the class.

          Also, you don't want Sun's j2ee.jar, use jboss-j2ee.jar

          Regards,
          Adrian

          • 2. Re: Deployed OK but application client won't run
            Andrew Newbie

            Thanks for the response Adrian. Here are the contents of HelloWorld.jar:

            META-INF/
            META-INF/MANIFEST.MF
            com/
            com/mastertech/
            com/mastertech/sample/
            com/mastertech/sample/HelloWorld.class
            com/mastertech/sample/HelloWorldBean.class
            com/mastertech/sample/HelloWorldHome.class
            META-INF/ejb-jar.xml

            As you can see there is no jboss.xml but going by the tutorial I was following this is not necessary for such a simple example. Here is ejb-jar.xml:

            <?xml version="1.0" encoding="UTF-8"?>

            <ejb-jar>
            JBOSS Hello World Wpplication
            <display-name>Hello World EJB</display-name>
            <enterprise-beans>

            <ejb-name>Hello</ejb-name>
            com.mastertech.sample.HelloWorldHome
            com.mastertech.sample.HelloWorld
            <ejb-class>com.mastertech.sample.HelloWorldBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Bean</transaction-type>

            </enterprise-beans>
            </ejb-jar>

            Here is the application client code:
            Note I have not imported the Remote and Home interface as the client is in the same package as the EJB. Not very realistic I know but this was supposed to be a quick sample to get started!

            package com.mastertech.sample;

            /** application client **/

            import javax.naming.Context;
            import javax.naming.InitialContext;
            import java.util.Hashtable;

            public class HelloWorldClient{
            public static void main(String [] args){
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            env.put(Context.PROVIDER_URL, "LOCALHOST:1099");
            env.put("java.naming.factoy.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
            try{
            Context ctx = new InitialContext(env);
            Object obj = ctx.lookup("HelloWorld");
            HelloWorldHome home = (HelloWorldHome)
            javax.rmi.PortableRemoteObject.narrow(obj, HelloWorldHome.class);
            HelloWorld helloWorld = home.create();
            System.out.println(helloWorld.sayHello());
            helloWorld.remove();
            }
            catch(Exception e){
            e.printStackTrace();
            System.out.println("Exception: "+ e.getMessage());
            }
            }
            }

            I also took Sun’s j2ee.jar out of the classpath and left in jboss-j2ee.jar in it. Unfortunately I am still getting the same error.

            Can anyone spot any mistakes In the above code?

            Andrew

            • 3. Re: Deployed OK but application client won't run
              Peter Doornbosch Apprentice

              > Can anyone spot any mistakes In the above code?

              Yep: you are trying to start HelloWorldClient and that class is not in the jar (according to your listing of the jar contents).

              Cheers,
              Peter.

              • 4. Re: Deployed OK but application client won't run
                Andrew Newbie

                Peter,

                The reason there is no HelloWorldClient in the jar is that it is not part of the EJB. It is a stand-alone application client, which I am trying to run directly from the command line.
                Thanks for the advice though. Maybe I should try packaging the whole lot in an EAR file.

                Andrew

                • 5. Re: Deployed OK but application client won't run
                  Peter Doornbosch Apprentice

                  Hi Andrew,

                  You are right that there is no need to package the HelloWorldClient in the ear file; however, if you want to run it from the commandline, you have to make sure the class is on the classpath, right?! According to your 1st post, your classpath just contains jboss jars and your HelloWorld.jar, which - according to your 2nd post, just contains the bean classes. That won't work, that's what i was trying to say. Sorry that i didn't make myself clear.

                  So, just add the HelloWorldClient.class to the classpath mentioned in the 1st post before running the stand-alone client. That should be enough...

                  Hth
                  Peter.