cancel
Showing results for 
Search instead for 
Did you mean: 

EJB problem

Former Member
0 Kudos

Hi All,

I have EJB as a model(Simple Sum calc) . I created an ear file and deployed in the SAP J2EE engine.

I wrote a simple class to access the business methods form EJb.

I get the following error: Initial Context exception .

1. I include the EJB( CaclEJB.jar) in the class path of the client program.

2. I added the propeties:

properties.put(Context.INITIAL_CONTEXT_FACTORY,

"com.inqmy.services.jndi.InitialContextFactoryImpl");

3. I had done the jndi look up (what was present in the Visual Administrator) e.g java:com/env/ejb/Cacl)

4. and the regular stuff.(Calling the home etc).

I get the Intial Context eception ,that the class not found exception related to Inital Context .

Please help me out.

Accepted Solutions (0)

Answers (3)

Answers (3)

siddharth_jain
Active Contributor
0 Kudos

Hi Somya,

To access 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 Kudos

Hi Soumya,

I think you are trying to call the EJB module from a Java file, and executing it as a Java Application on your machine.

When we execute (i.e. Run) the simple java class as a Java Application, it uses the local machine JVM for exceuting it, while the EJB has been deployed or registered on the server. Also, your local machine JVM cannot initialize the InitialContext object, and hence the error.

For filling the initial context so that it refers your WAS, please use the following help.sap.com link:

[Link for Reference|http://help.sap.com/saphelp_nw70/helpdata/EN/45/3dbb8ea82b6bf1e10000000a1553f6/frameset.htm]

With this, you will get an idea how to get the initial context.

Regards,

Alka.

siddharth_jain
Active Contributor
0 Kudos

Hi Somya,

Make sure that your Look Up string is Right and You have Included the sapJ2eeClient Jar in Your Project.

Regards,

Siddharth