rdy1437
asked on
problems with testing an ejb apps in eclipse ide?
Hi! I tried to do a simple application in ejb.Its a stateless session bean that just print a hello message.
Im using the sun one application server and i deployed my ejb apps using the deploytool.Im using the
eclipse ide.
I write a test application:
Context initContext = new javax.naming.InitialContex t();
String JNDIName = "java:comp/env/ejb/HelloBe an";
System.out.println("lookin g");
Object objref = initContext.lookup(JNDINam e);
HelloHome helloHome = (HelloHome)PortableRemoteO bject.narr ow(objref,
HelloHome.class);
System.out.println("looked ");
Hello hello = helloHome.create();
System.out.println("messag e " + hello.getMessage());
and when i run it i got an error:
javax.naming.NoInitialCont extExcepti on: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initia l
sun-ejb.jar.xml
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 EJB 2.1//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-ejb-jar_2_1-0.dtd">
<sun-ejb-jar>
<enterprise-beans>
<unique-id>1300025963</uni que-id>
<ejb>
<ejb-name>HelloBean</ejb-n ame>
<jndi-name>HelloBean</jndi -name>
<pass-by-reference>false</ pass-by-re ference>
<is-read-only-bean>false</ is-read-on ly-bean>
<refresh-period-in-seconds >-1</refre sh-period- in-seconds >
<cmt-timeout-in-seconds>0< /cmt-timeo ut-in-seco nds>
<gen-classes>
<remote-impl>simple.HelloB ean_EJBObj ectImpl</r emote-impl >
<remote-home-impl>simple.H elloBean_R emoteHomeI mpl</remot e-home-imp l>
</gen-classes>
<session>
<quick-checkpoint>true</qu ick-checkp oint>
</session>
</ejb>
</enterprise-beans>
</sun-ejb-jar>
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>Ejb1</displa y-name>
<enterprise-beans>
<session>
<ejb-name>HelloBean</ejb-n ame>
<home>simple.HelloHome</ho me>
<remote>simple.Hello</remo te>
<ejb-class>simple.HelloBea n</ejb-cla ss>
<session-type>Stateless</s ession-typ e>
<transaction-type>Bean</tr ansaction- type>
<security-identity>
<use-caller-identity/>
</security-identity>
</session>
</enterprise-beans>
</ejb-jar>
Any help? thanks.
raymond
Im using the sun one application server and i deployed my ejb apps using the deploytool.Im using the
eclipse ide.
I write a test application:
Context initContext = new javax.naming.InitialContex
String JNDIName = "java:comp/env/ejb/HelloBe
System.out.println("lookin
Object objref = initContext.lookup(JNDINam
HelloHome helloHome = (HelloHome)PortableRemoteO
HelloHome.class);
System.out.println("looked
Hello hello = helloHome.create();
System.out.println("messag
and when i run it i got an error:
javax.naming.NoInitialCont
sun-ejb.jar.xml
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 EJB 2.1//EN" "http://www.sun.com/software/sunone/appserver/dtds/sun-ejb-jar_2_1-0.dtd">
<sun-ejb-jar>
<enterprise-beans>
<unique-id>1300025963</uni
<ejb>
<ejb-name>HelloBean</ejb-n
<jndi-name>HelloBean</jndi
<pass-by-reference>false</
<is-read-only-bean>false</
<refresh-period-in-seconds
<cmt-timeout-in-seconds>0<
<gen-classes>
<remote-impl>simple.HelloB
<remote-home-impl>simple.H
</gen-classes>
<session>
<quick-checkpoint>true</qu
</session>
</ejb>
</enterprise-beans>
</sun-ejb-jar>
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>Ejb1</displa
<enterprise-beans>
<session>
<ejb-name>HelloBean</ejb-n
<home>simple.HelloHome</ho
<remote>simple.Hello</remo
<ejb-class>simple.HelloBea
<session-type>Stateless</s
<transaction-type>Bean</tr
<security-identity>
<use-caller-identity/>
</security-identity>
</session>
</enterprise-beans>
</ejb-jar>
Any help? thanks.
raymond
Yup, it would be better to use the provided constants, like:
env.put ( javax.naming.Context.PROVI DER_URL, "com.sun.jndi.cosnaming.CN CtxFactory " ) ;
env.put ( javax.naming.Context.INITI AL_CONTEXT _FACTORY, "iiop://server-name:port>" ) ;
- it would be even better to store the Provider-URL in a properties-file and read from there because if you deploy on something else (like Websphere), then the name will change.
env.put ( javax.naming.Context.PROVI
env.put ( javax.naming.Context.INITI
- it would be even better to store the Provider-URL in a properties-file and read from there because if you deploy on something else (like Websphere), then the name will change.
ASKER
Hi!
I tried to use this :
Properties env = new Properties();
env.put ( javax.naming.Context.INITI AL_CONTEXT _FACTORY, "com.sun.jndi.cosnaming.CN CtxFactory ") ;
env.put ( javax.naming.Context.PROVI DER_URL, "iiop://localhost:9090") ;
InitialContext initContext = new InitialContext(env);
but i got this error:
javax.naming.Communication Exception: Cannot connect to ORB [Root exception is org.omg.CORBA.COMM_FAILURE : vmcid: SUN minor code: 208 completed: Maybe]
at com.sun.jndi.cosnaming.CNC tx.setOrbA ndRootCont ext(Unknow n Source)
at com.sun.jndi.cosnaming.CNC tx.initUsi ngIiopUrl( Unknown Source)
at com.sun.jndi.cosnaming.CNC tx.initUsi ngUrl(Unkn own Source)
at com.sun.jndi.cosnaming.CNC tx.initOrb AndRootCon text(Unkno wn Source)
at com.sun.jndi.cosnaming.CNC tx.<init>( Unknown Source)
at com.sun.jndi.cosnaming.CNC txFactory. getInitial Context(Un known Source)
at javax.naming.spi.NamingMan ager.getIn itialConte xt(Unknown Source)
at javax.naming.InitialContex t.getDefau ltInitCtx( Unknown Source)
at javax.naming.InitialContex t.init(Unk nown Source)
at javax.naming.InitialContex t.<init>(U nknown Source)
my sun one server is running, access it thru http://localhost:9090
I tried to use this :
Properties env = new Properties();
env.put ( javax.naming.Context.INITI
env.put ( javax.naming.Context.PROVI
InitialContext initContext = new InitialContext(env);
but i got this error:
javax.naming.Communication
at com.sun.jndi.cosnaming.CNC
at com.sun.jndi.cosnaming.CNC
at com.sun.jndi.cosnaming.CNC
at com.sun.jndi.cosnaming.CNC
at com.sun.jndi.cosnaming.CNC
at com.sun.jndi.cosnaming.CNC
at javax.naming.spi.NamingMan
at javax.naming.InitialContex
at javax.naming.InitialContex
at javax.naming.InitialContex
my sun one server is running, access it thru http://localhost:9090
Try: env.put ( javax.naming.Context.PROVI DER_URL, "http://localhost:9090") ;
Hmm I don't think it's the same URL. It's definitely "iiop://localhost:" + port. I'm not very sure about which version of the Sun ONE you are running, so I don't know the port number. Give 3700 a try because IIRC that's the default.
ASKER
manifoldronin,
im using the one bundle with the j2ee1.4 installer
im using the one bundle with the j2ee1.4 installer
ASKER
i tried
env.put ( javax.naming.Context.PROVI DER_URL, "iiop://localhost:3700") ;
but got the following exception:
javax.naming.NameNotFoundE xception [Root exception is org.omg.CosNaming.NamingCo ntextPacka ge.NotFoun d: IDL:omg.org/CosNaming/Nami ngContext/ NotFound:1 .0]
env.put ( javax.naming.Context.PROVI
but got the following exception:
javax.naming.NameNotFoundE
Yeah, it should be "iiop://". I have never used "http:" - suggested that just in case.... because "iiop" did not seem to work. Are you sure your class-path is properly set? I mean - if you're using your own IDE, it would generally use its own classpath and not the system classpath.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks manifoldronin!
I used the following code and it works.
Properties env = System.getProperties();
env.setProperty( javax.naming.Context.INITI AL_CONTEXT _FACTORY, "com.sun.jndi.cosnaming.CN CtxFactory ") ;
env.setProperty( javax.naming.Context.PROVI DER_URL, "iiop://purple:3700") ;*/
InitialContext context = new InitialContext();
Object objref = context.lookup("HelloBean" );
System.out.println("Lookin g - " + context.getEnvironment());
System.out.println("Lookin g - " + objref );
I used the following code and it works.
Properties env = System.getProperties();
env.setProperty( javax.naming.Context.INITI
env.setProperty( javax.naming.Context.PROVI
InitialContext context = new InitialContext();
Object objref = context.lookup("HelloBean"
System.out.println("Lookin
System.out.println("Lookin
Properties env = new Properties();
env.put("java.naming.facto
env.put("java.naming.provi
InitialContext jndi = new InitialContext(env);