on 07-20-2007 2:09 PM
Hi everybody!
I created a Java DC that exposes some methods as a web service. This DC uses another Java DC accessing some database tables via jdbc. Now, I'm creating a "diagnosis" WS method to check if all database tables are accessible. Since the referenced DC may change without me being aware of, I'd like to check the corresponding package in that DC for classes implementing a certain interface, call a static method on each of there classes to retrieve the needed tables and then check if I can access these.
My build creates an ear file names "lvr.deecmZuWSO.ear" that is being deployed to my J2EE server "JP1". This ear file contains a jar file named "lvr.deecmZoBOJ~EcmZustBOAss.jar", which is the jar from my db accessing java DC. This jar in turn contains a directory "mvBusinessObjects" which contains the *.class files I'd like to instantiate.
To achieve that, I'm retrieving the URL for my package ressource (the package name "mvBusinessObjects" is sent as "name"), getting the File for that URL and finally I'm checking if the directory exists:
name = "/mvBusinessObjects";
URL url = EcmZuServiceWrapper.class.getResource(name);
File directory = new File(url.getFile());
if (directory.exists())
{
// load the classes defined in the *.class files in that directory and instantiate them.
}
else
{
// directory does not exist
}
Unfortunately, I always end up with a not existing directory; the values I get are
URL:
jar:file:/usr/sap/JP1/JC00/j2ee/cluster/server0/apps/lvr.de/ecmZuWSO/lvr.deecmZuBOJEcmZustBOAss.jar!/mvBusinessObjects
directory:
file:/usr/sap/JP1/JC00/j2ee/cluster/server0/apps/lvr.de/ecmZuWSO/lvr.deecmZuBOJEcmZustBOAss.jar!/mvBusinessObjects
and finally
Directory does not exist : file:/usr/sap/JP1/JC00/j2ee/cluster/server0/apps/lvr.de/ecmZuWSO/lvr.deecmZuBOJEcmZustBOAss.jar!/mvBusinessObjects
Any ideas what I'm doing wrong? Any other idea on how to achieve my goal (to be able to instantiate each class inside the "mvBusinessObjects" folder inside the .jar file inside the deployed .ear file ?
Hi Michael,
use a classloader [1] to access resources within your application. Try if
this.getClassloader().getResourceasStream(name);
// check the Stream for content
helps in your case.
Jan
[1] http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that's what I'm trying to do once I identified the name of the classes I'd like to load
The problem is to identify all classes within a package. Usually, the above construct gives me a path to the directory where my package is being installed so I can check all files within that directory with a .class extension, but I never tried that with a jar inside an ear file.
Do you know a way to get the class names for all classes of a package stored in a jar inside an ear ?
Thanks
Michael
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
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.