on 12-10-2005 3:07 PM - last edited on 02-04-2024 1:28 AM by postmig_api_4
Hello,
I have an stateless session bean, and I need to access some resources which I packaged in the resulting jar.
For example I have source package like this:
org.example.bean.*
org.example.files.*
In the code I thought that I will be able to access these files in common way:
String urlName = "org/example/files/file1"
URL resURL = this.getClass().getResource(urlName);
or
URL resURL = ClassLoader.getSystemResource(urlName);
but it don't work, everytime it returns null.
Maybe in EJB container the code like that dont function, I don't know but it's working in common java aplication so I thought it will be so also in ejb.
Can anyone tell me how can I access my files?
Any help would be appreciated.
Best Regards,
Miroslav Koskar
Hi Miroslav ,
Are you trying to access stateless session bean or classes
from a packaged jar into your stateless session bean?
If you are trying to access the stateless session bean,then you can go by the way Ray has suggested.
Or, if you are trying to access the classes inside a jar in you stateless session bean then here u go...
In your EJB->project->right clicj-> properties->java build path -> Add External Jars and add the desired jars.
Now you will be able to access it as you wanted.
Hope this suggestion helps.
Pl reward points if the suggestion helped you.
Thanks and regards
Deepa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ray, Deepa
My problem is not in accessing EJB from second EJB. I want to write in ejb bussiness method the code, in which I am accessing a set of files which are packaged in jar (EJB module). Lets imagine that these files are a 10 images and the bussiness method have to read a specified of them and then return it in own serialization implementation of image class to client. Now is my problem that I even cant load the image from file in EJB because I'm getting null URL object in above code.
If you have an idea what I'm doing wrong, please post.
Best regards,
Miroslav Koskar
To access methods in your bean from another program, you need to use JNDI to lookup the bean. On help.sap.com, you can search for "Enterprise Bean Clients" for more info. Also, here's some code that might help.
import java.rmi.RemoteException;
import java.util.*;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
Context ctx = new InitialContext(props);
Object o = ctx.lookup("mycomp.com/TheEAR/TheBean");
home = (ReportHome)
PortableRemoteObject.narrow(o, TheHome.class);
bean = home.create();
String myString = bean.myMethod();
The above assumes the name of the bean is TheBean and also assumes you a public method named myMethod in the bean that returns a String.
Ray
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 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.