5 Replies Latest reply on Nov 16, 2006 4:44 AM by Nikolaj G.

    Example: java.lang.NoClassDefFoundError (org/jboss/logging/L

    Nikolaj G. Newbie

      Hi JBoss workers,

      At first, Im quite new into JBoss. Im going to make an application (see Open socket and JBoss) that should have an open socket against JBoss (being able to send events, but also get notified).

      I managed to compile and deploy the Duke's Bank Application, but its a little bit to overwelming to begin with. Intead I found a simple example at http://www.ftponline.com/ (hope its okay that I post the example here).


      I get the following error, when I try to connect using the Client app. :

      Exception in thread "main" java.lang.NoClassDefFoundError:
      org/jboss/logging/Logger
      at org.jnp.interfaces.NamingContext.(NamingContext.java:158)
      at org.jnp.interfaces.NamingContextFactory.getInitialContext(NamingContextFactory.java:56)
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.InitialContext.(Unknown Source)
      at Client.main(Client.java:25)

      ------------------------------------------------------------
      .\Client.java:

      import javax.naming.*;
      import javax.rmi.PortableRemoteObject;
      import java.util.Properties;
      import com.javapro.ejb.StringProcessor;
      import com.javapro.ejb.StringProcessorHome;

      public class Client {

      public static void main(String[] args) {

      // first argument must be the input
      if (args.length==0) {
      System.out.println("Please specify the input to convert to upper case.");
      return;
      }
      String input = args[0];

      // preparing properties for constructing an InitialContext object
      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.PROVIDER_URL, "localhost:1099");

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

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

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

      // Create an Adder object from the Home interface
      StringProcessor sp = home.create();
      System.out.println ("Uppercase of '" + input + "' is " +
      sp.toUpperCase(input));
      }
      catch(Exception e) {
      System.out.println(e.toString());
      }
      }
      }

      ------------------------------------------------------------
      META-INF\ejb-jar.xml:

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

      <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

      <ejb-jar>
      Your first EJB application
      <display-name>String Processor Application</display-name>
      <enterprise-beans>

      <ejb-name>StringProcessor</ejb-name>
      com.javapro.ejb.StringProcessorHome
      com.javapro.ejb.StringProcessor
      <ejb-class>com.javapro.ejb.StringProcessorBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>

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


      ------------------------------------------------------------
      .\com\javapro\ejb\StringProcessor.java:

      package com.javapro.ejb;

      import javax.ejb.EJBObject;
      import java.rmi.RemoteException;

      public interface StringProcessor extends EJBObject {
      public String toUpperCase(String s) throws RemoteException;
      }


      ------------------------------------------------------------
      .\com\javapro\ejb\StringProcessorHome.java:

      package com.javapro.ejb;

      import java.rmi.RemoteException;
      import javax.ejb.CreateException;
      import javax.ejb.EJBHome;

      public interface StringProcessorHome extends EJBHome {
      StringProcessor create() throws RemoteException, CreateException;
      }

      ------------------------------------------------------------
      .\com\javapro\ejb\StringProcessorBean.java:

      package com.javapro.ejb;

      import java.rmi.RemoteException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;

      public class StringProcessorBean implements SessionBean {

      public String toUpperCase(String s) {
      System.out.println("from StringProcessorBean");
      if (s==null)
      return null;
      else
      return s.toUpperCase();
      }

      public void ejbCreate() {
      }

      public void ejbRemove() {
      }

      public void ejbActivate() {
      }

      public void ejbPassivate() {
      }

      public void setSessionContext(SessionContext sc) {
      }
      }


      ------------------------------------------------------------
      .\Compile.bat:

      javac -classpath C:\jboss-4.0.5.GA\client\jboss-j2ee.jar com/javapro/ejb/StringProcessor.java
      javac -classpath C:\jboss-4.0.5.GA\client\jboss-j2ee.jar;. com/javapro/ejb/StringProcessorHome.java
      javac -classpath C:\jboss-4.0.5.GA\client\jboss-j2ee.jar;. com/javapro/ejb/StringProcessorBean.java
      javac -classpath C:\jboss-4.0.5.GA\client\jboss-j2ee.jar;C:\jboss-4.0.5.GA\client\jbossall-client.jar;. Client.java

      ------------------------------------------------------------
      .\MakeJar.bat:

      jar cfv StringProcessor.jar com/javapro/ejb/*.class META-INF/ejb-jar.xml


      Thanks in advance, Nikolaj, Copenhagen