Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Executing HelloWorld program in EJB java.lang.NoClassDefFoundError-help plz

843830Jun 29 2005 — edited Jul 5 2005
Hi

I am a tyro to Weblogic 8.1 server with EJB. I am Running a simple HeloWorld program ,but it throws No class def found err. Below i listed my program.help needed.

Home interface
package examples;

import java.rmi.*;
import javax.ejb.*;
public interface HelloWorldHome extends EJBHome {
public HelloWorld create() throws CreateException,RemoteException;
}
Remote interface:
package examples;
import java.rmi.*;
import javax.ejb.*;
public interface HelloWorld extends EJBObject
{
public String getHelloWorldMsg () throws RemoteException;
}
HelloWorldLocal-- Remote
package examples;

import javax.ejb.*;
public interface HelloWorldLocal extends EJBLocalObject
{
public String getHelloWorldMsg();
}

HelloWorldLocalHome:
package examples;

import javax.ejb.*;
public interface HelloWorldLocalHome extends EJBLocalHome
{
HelloWorldLocal create() throws CreateException;
}

HelloWorldBean:
package examples;

import javax.ejb.*;
import javax.SessionContext;
public class HelloWorldBean implements SessionBean
{
public HelloWorldBean() {}
private void log(String s) {
if (true) System.out.println(s);
}


public void ejbActivate() {}

public void ejbPassivate() {}
public void ejbRemove() {
log("ejbRemove() called");
}
public void setSessionContext(SessionContext ctx) {
log("setSessionContext called");
this.ctx = ctx;
}
public void ejbCreate() throws CreateException {
log("ejbCreate() called");
}
public String getHelloWorldMsg () {
log("Bean Method called");
return ("Stateless SessionBean says Hello World");
}
}

Client program
package examples;

import java.rmi.*;
import javax.rmi.PortableRemoteObject;
import javax.naming.*;
import java.util.*;
import examples.HelloWorldHome;
import examples.HelloWorld;
/**
* This class is an example of client code that calls
* methods on a simple stateless session bean.
*/
public class HelloWorldClient {

private static Context createJNDIContext()
throws NamingException, RemoteException {

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL,"t3://localhost:7001");

Context context = new InitialContext( env );
return context;
}
/**
* Main method to unit test the HelloWorld API
*/

public static void main(String[] args) {
try
{

// use JNDI to look up the home interface for HelloWorld
Context context = createJNDIContext();

// You could use the following statement to retrieve
// the HelloWorld home

/* HelloWorldHome home =
(HelloWorldHome)
context.lookup("examples.HelloWorldHome"); */

// However, using javax.rmi.PortableRemoteObject
// allows you to narrow the scope
// to the home interface

HelloWorldHome home = (HelloWorldHome )
PortableRemoteObject.narrow(
context.lookup("examples.HelloWorldHome"),
examples.HelloWorldHome.class ) ;


HelloWorld hello = home.create();

/*
* The EJBObject will delegate the call to the HelloWorld
* session bean, receive the result, and return it to this client.
*/

System.out.println(hello.hello());

/*
* Remove the EJBObject.
* The container will mark the EJBObject for destruction.
*/
hello.remove();
}
catch( Exception err )
{
System.err.println( err.toString() );
}
}
}

and also i put Class path in sys variables.I don't know reason y not running .help needed.

bye
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 2 2005
Added on Jun 29 2005
4 comments
521 views