cancel
Showing results for 
Search instead for 
Did you mean: 

Checking package contents

michael_voss2
Participant
0 Kudos

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 ?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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

michael_voss2
Participant
0 Kudos

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

Former Member
0 Kudos

jar file is zip-archive, you can try to use ZipInputStream to get it content

michael_voss2
Participant
0 Kudos

Yes, when accessing my jar as ZipFile everything workes fine, once I manipulated the path to that file since URL and File (even with File.getAbsolutePath()) gave somewhat unuseable results.

Now everything works fine. Thanks!