1 2 Previous Next 28 Replies Latest reply on Apr 29, 2008 1:04 AM by jaikiran

    running EJB pplication in jboss giving NoClassDefFoundError

    shiveeta

      Hi,

      I am a new user of jboss. I tried deploying a sample EJB apllication by following the tutorial at :- http://www.huihoo.org/jboss/online_manual/2.4/ch01s15.html . I was able to deploy the application in jboss <4.2.2GA> . but on calling EJB via a simple client, I face the following exception :-
      interest-client:
      [java] hi
      [java] Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss
      /logging/Logger
      [java] at org.jnp.interfaces.NamingContext.(NamingContext.java:
      143)
      [java] at org.jnp.interfaces.NamingContextFactory.getInitialContext(Nam
      ingContextFactory.java:41)
      [java] at javax.naming.spi.NamingManager.getInitialContext(NamingManage
      r.java:667)
      [java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.
      java:247)
      [java] at javax.naming.InitialContext.init(InitialContext.java:223)
      [java] at javax.naming.InitialContext.(InitialContext.java:175)
      [java] at org.jboss.docs.interest.InterestClient.main(InterestClient.ja
      va:30)
      [java] Java Result: 1

      I tried googling and my classpath has jbossall-client.jar in it. However still facing this problem.

      The client code is :-
      package org.jboss.docs.interest;

      import javax.naming.InitialContext;
      import javax.rmi.PortableRemoteObject;

      import org.jboss.docs.interest.Interest;
      import org.jboss.docs.interest.InterestHome;

      /** This simple application tests the 'Interest' Enterprise JavaBean which is
      implemented in the package 'org.jboss.docs.interest'. For this to work, the
      Bean must be deployed on an EJB server.
      */
      class InterestClient
      {
      /** This method does all the work. It creates an instance of the Interest EJB on
      the EJB server, and calls its `calculateCompoundInterest()' method, then prints
      the result of the calculation.
      */
      public static void main(String[] args)
      {
      System.out.println("hi");

      // Enclosing the whole process in a single `try' block is not an ideal way
      // to do exception handling, but I don't want to clutter the program up
      // with catch blocks
      InitialContext jndiContext=null;
      try
      {
      // Get a naming context
      jndiContext = new InitialContext();
      System.out.println("Got context");

      }
      catch(Exception e)
      {
      System.out.println("I am here!!");
      e.printStackTrace();
      }

      try
      {

      // Get a reference to the Interest Bean
      Object ref = jndiContext.lookup("interest/Interest");
      System.out.println("Got reference");

      // Get a reference from this to the Bean's Home interface
      InterestHome home = (InterestHome)
      PortableRemoteObject.narrow(ref, InterestHome.class);

      // Create an Interest object from the Home interface
      Interest interest = home.create();

      // call the calculateCompoundInterest() method to do the calculation
      System.out.println("Interest on 1000 units, at 10% per period, compounded over 2 periods is:");
      System.out.println(interest.calculateCompoundInterest(1000, 0.10, 2));
      }
      catch(Exception e)
      {
      System.out.println(e.toString());
      }
      }
      }



      Please guide in this ...Any help would be apprecitated. Thanks in advance.

        • 1. Re: running EJB pplication in jboss giving NoClassDefFoundEr
          shiveeta

          jndiContext = new InitialContext(); is the line in the client code , thats throwing this exception.

          • 2. Re: running EJB pplication in jboss giving NoClassDefFoundEr
            jaikiran

             

            I tried googling and my classpath has jbossall-client.jar in it. However still facing this problem.

            Are you sure the jbossall-client.jar is in the classpath of your InterestClient client? How have you added that jar to the classpath and how do you run the client?


            • 3. Re: running EJB pplication in jboss giving NoClassDefFoundEr
              shiveeta

              My classpath is :-
              .;%JBOSS_HOME%\client\jbossall-client.jar;%JBOSS_HOME%\lib;C:\Sun\AppServer\lib\j2ee.jar;
              I use ant tool to create the jar, then deploy it in jboss , and then to run the client. <ant-intro-interest-client >. ant refers to a build.xml used for same.

              • 4. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                jaikiran

                 

                %JBOSS_HOME%\client\jbossall-client.jar


                Are you sure the %JBOSS_HOME% is being correctly resolved? Why not try specifying the absolute path, in the classpath. Something like this:

                C:\JBoss-4.2.2\client\jbossall-client.jar


                • 5. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                  shiveeta

                  yes i am sure that its getting resolved correctly. i have set JBOSS_HOME also .

                  i had tried with absolute paths as well. But it wasnt wrking then either.

                  jndiContext = new InitialContext(); line is throwing exception.

                  any help from that??

                  • 6. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                    jaikiran

                    The classpath that you are setting, are you doing it as part of the build.xml? If yes, please post the build.xml contents.

                    While posting the logs or code or xml content, remember to wrap it in a code block using the Code button in the message editor window and please hit the Preview button to make sure your post is correctly formatted

                    • 7. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                      shiveeta

                      the classpath i am setting in My computer-> Properties -> Environment variables. the build.xml used is :-

                      <?xml version="1.0" encoding="UTF-8" ?>
                       <!--
                       Ant build file for the documentation tutorial code
                       Writer of a chapter with an example have to include a foroward
                       to their build file. This latest build file suppose arguments
                       sets here :
                       src.dir : Directory where the source are : manual\src\examples
                       build.dir : Base directory where to store generated files (class/ejb/war/...)
                       classpath : Classpath used to make any compilation (set up here by verifing
                       which version of JBoss is used.
                      
                       -->
                      
                       <project name="CMP" default="main" basedir="../">
                      
                       <property name="env" environment="env" value="" location=""/>
                       <!-- Override with your JBoss server dist location if the JBOSS_DIST env var is not set -->
                       <property name="jboss.dist" value="${env.JBOSS_DIST}"/>
                       <!-- Override with your web server servlet jar location. The default assumes that
                       JBOSS_DIST points to a JBoss/Tomcat bundle distribution
                       -->
                       <property name="servlet.jar" value="${env.JBOSS_DIST}}/../tomcat/lib/servlet.jar"/>
                       <property name="src.dir" value="${basedir}"/>
                       <property name="src.resources" value="${basedir}/resources"/>
                       <property name="build.dir" value="${basedir}/build-examples"/>
                       <property name="dist.dir" value="${basedir}/../../dist-examples"/>
                      
                       <path id="base.path_22">
                       <pathelement location="${jboss.dist}/client/ejb.jar"/>
                       <pathelement location="${jboss.dist}/client/jaas.jar"/>
                       <pathelement location="${jboss.dist}/client/jbosssx-client.jar"/>
                       <pathelement location="${jboss.dist}/client/jboss-client.jar"/>
                       <pathelement location="${jboss.dist}/client/jnp-client.jar"/>
                       <pathelement location="${servlet.jar}"/>
                       </path>
                       <path id="base.path_23">
                       <pathelement location="${jboss.dist}/client/jboss-j2ee.jar"/>
                       <pathelement location="${jboss.dist}/client/jaas.jar"/>
                       <pathelement location="${jboss.dist}/client/jbosssx-client.jar"/>
                       <pathelement location="${jboss.dist}/client/jboss-client.jar"/>
                       <pathelement location="${jboss.dist}/client/jnp-client.jar"/>
                       <pathelement location="${servlet.jar}"/>
                       </path>
                      
                       <target name="validate">
                       <available property="classpath_id" value="base.path_22" file="${jboss.dist}/client/ejb.jar" />
                       <available property="classpath_id" value="base.path_23" file="${jboss.dist}/client/jboss-j2ee.jar" />
                       </target>
                      
                       <target name="fail_if_not_valid" unless="classpath_id">
                       <fail message="jboss.dist=${jboss.dist} is not a valid JBoss dist directory"/>
                       </target>
                      
                       <target name="init" depends="validate,fail_if_not_valid">
                       <property name="classpath" refid="${classpath_id}" />
                       <echo message="Using JBoss directory=${jboss.dist}" />
                       <echo message="Using base classpath=${classpath}" />
                       <echo message="Using Source directory=${src.dir}" />
                       <echo message="Using Build directory=${build.dir}" />
                       </target>
                      
                       <!-- Clean build and dist -->
                       <target name="clean" depends="init">
                       <delete dir="${build.dir}"/>
                       <delete dir="${dist.dir}"/>
                       </target>
                      
                       <!-- No default Target -->
                       <target name="main" depends="init">
                       <echo message="Specify which target you want to run. Example: build cmp-cd-list" />
                       </target>
                      
                       <!-- Target to create files to store on the Web site -->
                      
                       <target name="dist" depends="clean">
                       <mkdir dir="${dist.dir}"/>
                       <!-- Bundle all the sources and build script in one file -->
                       <zip zipfile="${dist.dir}/documentation-example.zip" basedir="${src.dir}/../"
                       includes="examples/**" />
                       <tar tarfile="${dist.dir}/documentation-example.tar" basedir="${src.dir}/../"
                       includes="examples/**" />
                       <gzip src="${dist.dir}/documentation-example.tar" zipfile="${dist.dir}/documentation-example.tar.gz" />
                       <!-- Add Chapter specific files here
                       <antcall target="cmp-cd-dist" />
                       -->
                       </target>
                      
                       <!-- *************************************************************************** -->
                       <!-- Chapter 1 - First Steps -->
                       <target name="intro-interest-compile" depends="init">
                       <ant antfile="org/jboss/docs/interest/build.xml" target="compile" />
                       </target>
                      
                       <target name="intro-interest-jar" depends="init">
                       <ant antfile="org/jboss/docs/interest/build.xml" target="ejb-jar" />
                       </target>
                      
                       <target name="intro-interest-ear" depends="init">
                       <ant antfile="org/jboss/docs/interest/build.xml" target="ear" />
                       </target>
                      
                       <target name="intro-interest-deploy" depends="init">
                       <ant antfile="org/jboss/docs/interest/build.xml" target="deploy-ejb-jar" />
                       </target>
                      
                       <target name="intro-interest-client" depends="init">
                       <ant antfile="org/jboss/docs/interest/build.xml" target="interest-client" />
                       </target>
                      
                      
                      
                       </project>
                       
                      


                      • 8. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                        jaikiran

                         

                        "Shiveeta" wrote:
                        the classpath i am setting in My computer-> Properties -> Environment variables.


                        That's not going to work. You have to create a classpath element through your Ant build file and use it in the task while invokes the client. See the Ant documentation for more details about how to create and use a classpath.


                        • 9. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                          shiveeta

                          ok will chk that out.
                          However whil running the ant command i got a message indicating that the classpath is being picked :- <Using base Classpath>

                          .

                          D:\shivi_wrk_ejb\documentation-example\examples\build>ant intro-interest-client
                          Buildfile: build.xml
                          
                          validate:
                          
                          fail_if_not_valid:
                          
                          init:
                           [echo] Using JBoss directory=D:\downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.
                          GA
                           [echo] Using base classpath=D:\downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.G
                          A\client\jboss-j2ee.jar;D:\downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.GA\client\
                          jaas.jar;D:\downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.GA\client\jbosssx-client.
                          jar;D:\downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.GA\client\jboss-client.jar;D:\
                          downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.GA\client\jnp-client.jar;D:\downloads
                          \JBoss\jboss-4.2.2.GA\tomcat\lib\servlet.jar
                           [echo] Using Source directory=D:\shivi_wrk_ejb\documentation-example\exampl
                          es
                           [echo] Using Build directory=D:\shivi_wrk_ejb\documentation-example\example
                          s/build-examples
                          
                          intro-interest-client:
                          
                          compile:
                          
                          interest-client:
                           [java] Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss
                          /logging/Logger
                           [java] at org.jnp.interfaces.NamingContext.<clinit>(NamingContext.java:
                          160)
                           [java] at org.jnp.interfaces.NamingContextFactory.getInitialContext(Nam
                          ingContextFactory.java:56)
                           [java] at javax.naming.spi.NamingManager.getInitialContext(NamingManage
                          r.java:667)
                           [java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.
                          java:247)
                           [java] at javax.naming.InitialContext.init(InitialContext.java:223)
                           [java] at javax.naming.InitialContext.<init>(InitialContext.java:175)
                           [java] at org.jboss.docs.interest.InterestClient.main(InterestClient.ja
                          va:27)
                           [java] Java Result: 1
                          
                          BUILD SUCCESSFUL
                          Total time: 1 second


                          • 10. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                            jaikiran

                             

                            [echo] Using base classpath=D:\downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.G
                            A\client\jboss-j2ee.jar;D:\downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.GA\client\
                            jaas.jar;D:\downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.GA\client\jbosssx-client.
                            jar;D:\downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.GA\client\jboss-client.jar;D:\
                            downloads\JBoss\jboss-4.2.2.GA\jboss-4.2.2.GA\client\jnp-client.jar;D:\downloads
                            \JBoss\jboss-4.2.2.GA\tomcat\lib\servlet.jar


                            And as you can see, the jbossall-client.jar is not mentioned in this classpath.

                            • 11. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                              peterj

                              Did you examine the classpath that ant printed? Did you notice that jbossall-client.jar is not in that classpath? The jboss-client.jar file is there, but it is not the same as jbossall-client. Looking at your ant script, the jbossall-client.jar file is in neither of the class paths declared.

                              • 12. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                                shiveeta

                                thanks a lot for this clue.
                                That exception got resolved after setting jbossall-client.jar n ant's build.xml.

                                Now facing another error :-
                                [java] javax.naming.NameNotFoundException: interest not bound

                                any help again??
                                Thanks in advance..

                                • 13. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                                  shiveeta

                                  the exception is being thrown by :-
                                  Object ref = jndiContext.lookup("interest/Interest");

                                  in the client code.

                                  • 14. Re: running EJB pplication in jboss giving NoClassDefFoundEr
                                    shiveeta

                                    it seems to be some configuration issue ...in one of the xml files..but not able to figure out..any help on that ?

                                    1 2 Previous Next