Create EAR project
Create EJB project
Create session EJB
Add Session EJB method implementation
package dave;
import javax.ejb.Stateless;
/**
* Session Bean implementation class TestSesssionEJB
*/
@Stateless(mappedName = "TestSesssionEJB")
public class TestSesssionEJB implements TestSesssionEJBRemote, TestSesssionEJBLocal {
/**
* Default constructor.
*/
public TestSesssionEJB() {
}
public String hello(String name){
System.out.println("Hello" + name);
return name;
}
}
Add EJB project into EAR
Run on Server - deployment
Create wlfullclient.jar by running in $WLS_HOME/server/lib
java -jar wljarbuilder.jar
Add wlfullclient.jar and testEJB project to client classpath
Create client class
Get EJB name from JNDI tree
Create client implementation
package dave;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class TestClient {
private static String INITIAL_CONTEXT_NAME = "weblogic.jndi.WLInitialContextFactory";
private static String PROVIDER_URL = "t3://localhost:7001";
private static String JNDI_NAME = "TestSesssionEJB#dave.TestSesssionEJBRemote";
public static void main(String[] args) throws Exception {
Context ctx = getInitialContext();
TestSesssionEJBRemote testEJB = (TestSesssionEJBRemote) ctx
.lookup(JNDI_NAME);
System.out.println("Say hello: " + testEJB.hello("dave"));
}
private static Context getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_NAME);
env.put(Context.PROVIDER_URL, PROVIDER_URL);
return new InitialContext(env);
}
}
Check server log
<Nov 27, 2010 8:44:32 AM CET> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING>
<Nov 27, 2010 8:44:32 AM CET> <Notice> <WebLogicServer> <BEA-000360> <Server started in RUNNING mode>
Nov 27, 2010 8:44:42 AM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Sun's JavaServer Faces implementation (1.2_03-b04-FCS) for context '/console'
Nov 27, 2010 8:44:42 AM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Completed initializing Sun's JavaServer Faces implementation (1.2_03-b04-FCS) for context '/console'
Hellodave
Hi
ReplyDeleteGood document.
I don't know whether this will be of any use to future readers .. but for those getting the following error:
ReplyDeletejava.lang.NoClassDefFoundError: weblogic/kernel/KernelStatus
The following is needed to fix the error:
In the classpath tab, be sure to add the wlclient.jar file located here \wlserver_10.3\server\lib to the User Entries section and remove the WebLogic System Libraries from the Bootstrap Entries section. If you forget to remove the WebLogic System Libraries, you will get a stack like this: Exception in thread "Main Thread" java.lang.NoClassDefFoundError: weblogic/kernel/KernelStatus
The above is applicable to the client project created in the last few steps ( the one with the jndi lookup code)
ReplyDelete