on 11-15-2005 12:48 AM
Hello,
I have created and deployed an EJB to the WebAS (ver 6.40). There is no problem looking up the bean via JNDI and calling its methods from a J2EE application - I successfully did this via a servlet.
However, a JNDI lookup from a Web Dynpro application - on the same server - results in a java.lang.NoClassDefFoundError error.
The code for the JNDI lookup is identical in either case.
Any thoughts?
Hello all,
Thanks for your suggestions. I am looking up my bean using the following code:
Context jndiContext = new InitialContext();
SAPEmployeeLocalHome employeeLocalHome = (SAPEmployeeLocalHome) jndiContext.lookup("localejbs/SAPEmployeeBean");
This code works perfectly fine within my J2EE application, but within Web Dynpro I'm getting a java.lang.NoClassDefFoundError exception.
I have set the project references in my Web Dynpro project to reference both the EJB and the EAR projects where my bean is contained.
I have not deployed any of these in DCs (we are not using JDI) - they are all standalone apps. I don't think that this should make a difference - but could it?
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michael,
You need to specify webdynpro reference for your EJB application in Webdynpro project.
Goto Webdynpro project properties. there choose webdynpro references and choose Sharing reference tab.
Add reference to your EJB application as follows:
sap.com/<EAR application name>
Regards,
Bhavik
Hi Micheal,
You have to create an entry in
Double click on the ejb-j2EE-engine.xml
On the right hand side expand the session beans and click on the bean name
You have the option for entering the JNDI name
Then go to the webdynpro project right click and select the properties and select java build path for getting the bean class reference at runtime
Also go to project refernces and add the ejb project
Go to webdynpro refernces->sharing references and add "sap.com/<EAR project name>"
Write the code wherever you want to call the bean
Also create bean_att .Select type to be bean name from java native type
InitialContext ic = new InitialContext();
Object obj = ic.lookup("<JNDI name>");
<bean>Home home =(<bean>Home) PortableRemoteObject.narrow(obj,<bean>Home.class);
<bean> bean = home.create();
wdContext.currentContextElement().setBean_att(bean);
Once the bean instance has been set to bean_att
you can access the bean methods by
wdContext.currentContextElement().getBean_att().<method name>()
Hope this helps you
Regards
Rohit
Thank you very much Rohit and Bhavik, your answers solved my problem.
Could someone please explain to me the purpose of the "Sharing references" in my Web Dynpro application. In a J2EE application, all that is required is to set the "Project references". Do I need to set the "Sharing references" for every J2EE object on the server that I want to reference in my Web Dynpro (every servlet, EJB etc..) ?
Hi Micheal,
When you go to the Visual Administrator->Deploy->EJB Container you can see the names of all the deployed EARs under com.sap domain.Once you give the sharing reference the
Webdynpro application starts the lookup under the com.sap->your EAR folder
This sharing references is given so that 2 beans in different projects may have the same JNDI name.But in the same project they should have different names
Hope this helps you.
Regards
Rohit
Hello,
I am calling ejb from .jsp use following code
Properties props = new Properties();
InitialContext ctx = new InitialContext();
Object ob = ctx.lookup("java:comp/env/ejb/CalculatorBean");
CalculatorHome home = (CalculatorHome) PortableRemoteObject.narrow(ob, CalculatorHome.class);
calc = home.create();
I have a error:
java.lang.ClassNotFoundException: class com.sap.examples.calculator.beans.CalcProxy : com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at calculator, the whole lookup name is java:comp/env/ejb/CalculatorBean
My ejb-jar.xml is:
<display-name>
CalculatorEjb</display-name>
<enterprise-beans>
<session>
<icon/>
<ejb-name>Calculator</ejb-name>
<home>com.sap.examples.calculator.CalculatorHome</home>
<remote>com.sap.examples.calculator.CalculatorRemote</remote>
<local-home>com.sap.examples.calculator.CalculatorLocalHome</local-home>
<local>com.sap.examples.calculator.CalculatorLocal</local>
<service-endpoint>com.sap.examples.calculator.CalculatorServiceEndpoint</service-endpoint>
<ejb-class>com.sap.examples.calculator.CalculatorBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<ejb-ref-name>ejb/CalculatorBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.sap.examples.calculator.CalculatorHome</home>
<remote>com.sap.examples.calculator.CalculatorRemote</remote>
<ejb-link>Calculator</ejb-link>
</ejb-ref>
<ejb-local-ref>
<description/>
<ejb-ref-name>ejb/CalculatorBean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.sap.examples.calculator.CalculatorLocalHome</local-home>
<local>com.sap.examples.calculator.CalculatorLocal</local>
<ejb-link>Calculator</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
my ejb-j2ee-engine.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-j2ee-engine
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ejb-j2ee-engine.xsd">
<enterprise-beans>
<enterprise-bean>
<ejb-name>Calculator</ejb-name>
<ejb-ref>
<ejb-ref-name>ejb/CalculatorBean</ejb-ref-name>
<jndi-name>ejb/CalculatorBean</jndi-name>
</ejb-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/CalculatorBean</ejb-ref-name>
<jndi-name>ejb/CalculatorBean</jndi-name>
</ejb-local-ref>
</enterprise-bean>
</enterprise-beans>
</ejb-j2ee-engine>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thats because the Web dynpro runs in the its own runtime which is different than the servlet/ejb runtime.
Create a web service wrapper for the EJB and use this as a model to call from web dynpro or specify the PROVIDER_URL and port etc when you create an InitialContext.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Michael,
Just check if you've given the 'project reference 'properly. right click your webdynpro application , then click 'project refernce' given in the available options in the left hand side, now select the ejb project that you are trying to look up.
Regards,
Rahul.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Which JNDI name are you using to get the EJB? sometimes if you change the names of the JNDI in the Developer Studio you will have to use the different names. Anyway, you can see this JNDI name in the Visual Administrator unde:
-->Server X --> Service --> JNDI registry , and the look for the vendor (com.mycompany) and you will see all your JNDI name.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.