cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

JNDI InitialContext Error

Former Member
0 Likes
2,272

Hello Experts,

I have a little problem with my Java programm:

Test remote = null;

* try {*

// Create a new intial context, which loads from jndi.properties file.

* *

* Context ctx = new InitialContext();*

* System.out.println("Context:" + ctx);*

// Look up the home interface using the JNDI name.

// This JNDI lookup returns a reference to an EJBHome instance.

* TestHome home = (TestHome) ctx.lookup("sap.com/TestWorldEar/TestBean");*

* System.out.println("TestHome:" + home);*

// Create a session object.

* remote = home.create();*

* System.out.println("Remote:" + remote);*

// Invoke the remote EJB methods, test and debug.

* System.out.println("Result:" + remote.getWert());*

* } catch (Exception e) {*

* System.out.println("Exception: " + e.getLocalizedMessage());*

* }*

I always get the following error and I don't know how to solve the problem.

Exception: 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

I hope anybody of you can help me solving this problem.

Additional information:

The Java program is running on a XI (Netweaver 7.0).

I want to get information from a deployed EJB. The Bean still works.

Thank you for your answers in advance!!!

Greetings, Alexander

View Entire Topic
siddharth_jain
Active Contributor
0 Likes

Hi,

if you are accessing the EJB instance from your standalone java application you can try the following:-

String url = server + ":" + port;

Properties properties = new Properties();

properties.put(Context.INITIAL_CONTEXT_FACTORY,

"com.sap.engine.services.jndi.InitialContextFactoryImpl");

properties.put(Context.PROVIDER_URL, url);

//properties.put (Context.SECURITY_PRINCIPAL, "Administrator");

//properties.put(Context.SECURITY_CREDENTIALS, "password_here");

properties.put("force_remote", "true");

intialcontext = new InitialContext(properties);

You can try without force_remote property as well i think it should work.

by doing this you can get the initial context now you have to look up your ejb accordingly .

Check this SAP help on how to Look UP Remote and Local interfaces of EJB.

http://help.sap.com/saphelp_nw04/helpdata/en/38/3e5a4201301453e10000000a155106/frameset.htm

See the "Lookup from a Non-J2EE Java Application " section of the above link i think you should lookup your EJB using the approaches given in this section .

Hope This will help.

Regards,

Siddharth

Former Member
0 Likes

Hi Siddarth,

I already tested all of your answers but nothing of that work. But I am now sure that I won't get the JNDI context. But I dont know why.

My code is actually looking like this:

String contextFactory = "com.sap.engine.services.jndi.InitialContextFactoryImpl";

System.out.println ("contextfactory" + contextFactory );

Properties properties = new Properties();

properties.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);

//properties.put("force_remote", "true");

properties.put(Context.PROVIDER_URL, "server_url");

properties.put(Context.SECURITY_PRINCIPAL, "user");

properties.put(Context.SECURITY_CREDENTIALS, "password");

Context ctx = new InitialContext(properties);

System.out.println("Context:" + ctx);

// Look up the home interface using the JNDI name.

// This JNDI lookup returns a reference to an EJBHome instance.

TestHome home = (TestHome) ctx.lookup("sap.com/TestWorldEar/TestBean");

System.out.println("TestHome:" + home);

// Create a session object.

remote = home.create();