This a stand-alone client a POJO BTest.java trying a lookup() in
the Session Bean BBean.java the error is :
javax.naming.NoInitialContextException.
I need to fix the JNDI lookup()
A project
|
|
A-ejb
|
|
Source Packages
|
|
ejb |
BBean.java
BRemote.java
BTest.java
Right click ejb New------>File/Folder----------->
Java Classes-------->Java Main Class
Creates a new Java class with a main method permitting it to be run as a console
application.
The Remote interface(I tried also with Local interface ,same result) :
package ejb;
import javax.ejb.Remote;
public interface BRemote{ }
The Session Bean :
package ejb;
import javax.ejb.Stateless;
@Stateless(name="X")
public class BBean implements ejb.Remote{
public BBean(){ }
}
Is a useless Bean ,but my point is to try the Context with BTest.java
OK this Btest is a POJO so i can not use Direct Injection,I will try l to get the Context.
package ejb;
import java.util.loggin.Level;
import java.util.loggin.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class BTest{
public BTest(){ }
public static void main(
String [] args){
BTest cc=new BTest();
BRemote dd=(BRemote)cc.lookupX();
}
private BRemote lookupX(){
try{
Context c=new InitialContext();
return (ejb.BRemote)c.lookup("java:comp/env/ejb/"X");
}catch(NamingException ne){
Logger.getLogger(getClass().getName().log(Level.SEVERE,"exception caught",ne);
throw new RuntimeException(ne);
}
}end of class
Then I deployed A project OK no problem
I go to Run File (Shift +F6) :Run BTest.java
I got:
ejb.cc lookupX
Severe: exception caught
javax.naming.NoInitialException
This lookupX() was generated by the
IDE right click in the BTest{} class-------Enterprise Resources--->Call Enterprise Bean
How can I get it right with Netbeans?
The tutorial is great and works,but in this simple code not.
Thanks.
