• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

NoInitialContextException: Prob

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Bean Code :

i create a stateless session bean and in that include 2 method of String getInfo() and setInfo(String info) and process is same like create a bean int netbeans5.0 beta version.

and we user netbean 5.0 beta and jboss server

and my client code is

package cartclient;

import cart.CartRemote;
import cart.CartRemoteHome;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class Main {


public static void main(String[] args) {

try{

Context con = new InitialContext();
Object objRef = con.lookup("ejb/CartBean");
CartRemoteHome home = (CartRemoteHome)PortableRemoteObject.narrow(objRef,CartRemoteHome.class);

CartRemote cartremote = home.create();

cartremote.setInfo("Hello call a ejb method ") ;
System.out.println("The Message From Bean " + cartremote.getInfo());




}catch(Exception ex){
System.out.println("The Error : " + ex);
}

}

}


but i have error is

The Error : javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial


plz, help me to find a error and solve that propb.



thanks

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
instead of Object objRef = con.lookup("ejb/CartBean");

try: Object objRef = con.lookup("env/comp/ejb/CartBean");

not sure but worth trying....
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might have to set some properties in jndi.properites
Like:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099

And please change your name according to the policy :
http://www.javaranch.com/name.jsp
Thanks.
[ April 03, 2006: Message edited by: Satou kurinosuke ]
 
charmy jain
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

i try it and it is not work.
 
charmy jain
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try to change a name but it is not work and again i will try then it is work now... ok

thnaks for inform me...

and plz, help for solved a prob because it is also not wark
i prepare stateless session bean into netbeans id and compile it and i used a jboss server and now i want to call that it's ejb methods from simple java class meanse void main method so what i do??

plz, reply me
thnaks
 
charmy jain
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,


i got a soluction of my problem , so soluction is :


package com;

import com.sun.rsasign.c;
import javax.naming.InitialContext;

/**
*
* @author Shivam1
*/
public class testbean {

/** Creates a new instance of testbean */
public testbean() {

try{

com.exampleRemote updateAvailableBudgetRemote = lookupexampleBean() ;

System.out.println(updateAvailableBudgetRemote.getInfo());

}catch(Exception ex){
System.out.println(ex);
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
testbean t1 = new testbean();
}

private com.exampleRemote lookupexampleBean() {
try {

InitialContext ctx = new InitialContext();
ctx.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
ctx.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces");
ctx.addToEnvironment("java.naming.provider.url","localhost");

Object remote = ctx.lookup("test/Tester");
com.exampleRemoteHome rv = (com.exampleRemoteHome) javax.rmi.PortableRemoteObject.narrow(remote, com.exampleRemoteHome.class);
return rv.create();
}
catch(javax.naming.NamingException ne) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
throw new RuntimeException(ne);
}
catch(javax.ejb.CreateException ce) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce);
throw new RuntimeException(ce);
}
catch(java.rmi.RemoteException re) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,re);
throw new RuntimeException(re);
}
}


}


and plz define , "test/Tester" is jndi name into jboss.xml file at ejb module..


hahaha
u got a result


 
reply
    Bookmark Topic Watch Topic
  • New Topic