cancel
Showing results for 
Search instead for 
Did you mean: 

Referring EJB from JAVA class

Jan_Vandieken
Explorer
0 Kudos

Hello,

I try to instantiate an EJB in a normal JAVA class. I use the following code:

try {

javax.naming.Context ctx = new javax.naming.InitialContext();

Object ob = ctx.lookup("CALCULATOR_BEAN");

CalculatorHome home =

(org.example.calculator.ejb.CalculatorHome) javax.rmi.PortableRemoteObject.narrow(

ob,

org.example.calculator.ejb.CalculatorHome.class);

//Initialize the enterprise bean

calc = home.create();

} catch (Exception e) {

throw new Exception("Error while instantiating " + e.getMessage());

}

In the used DCs of the JAVA file all PPs of the EJB are added. I deploy the JAVA file using a serverside library and call its functionality from a WebDynpro.

When I run the component which uses the JAVA file I get a runtime Exception, which says:

java.lang.NoClassDefFoundError: org.example.calculator.ejb.CalculatorHome

referring to the codeline

CalculatorHome home =

(org.example.calculator.ejb.CalculatorHome) javax.rmi.PortableRemoteObject.narrow(

ob,

org.example.calculator.ejb.CalculatorHome.class);

Actuelly I use SP08.

How can I solve this problem ?

Thanks & regards

Jan

Accepted Solutions (0)

Answers (1)

Answers (1)

htammen
Active Contributor
0 Kudos

Hi Jan,

did you enclose the client.jar of your EJB project into the library project?

You can also set a reference to your EAR application within the server/provider.xml of your library project (reference tab).

Hope that helps

Helmut

Jan_Vandieken
Explorer
0 Kudos

Hello Helmut,

I added the client PP of the EJB but it still doesn't work.

What do you mean by

"You can also set a reference to your EAR application within the server/provider.xml of your library project (reference tab)."

In my library I can't find an xml file for editing the referenced EAR application.

So far

Jan

htammen
Active Contributor
0 Kudos

Hi Jan,

I thought you created a J2EE library project, added the jar file that contains your java class to this project and deployed it on the server.

In that case you should see your library in the Visual Admin under /serverXXX/libraries.

You can use such a library from any other application that resides on the J2EE server by referencing it.

But it seems that you didn´t use such a library project. But what do you mean with "I deploy the JAVA file using a serverside library and call its functionality from a WebDynpro".

Regards

Helmut

Jan_Vandieken
Explorer
0 Kudos

Hello Helmut,

after a closer look I found the problem. I have to include the EJB jar into the used DCs of my WebDynpro DC. This way it works.

Thanks for your help.

Regards Jan