jar problem: getResouces given a directory returning null

Hi, i am having problems with trying to get files from a directory inside the jar.

In my jar there is the following:

manifest.mf

.classpath

.project

com/dceg/rules/validator.java (main class)

com/dceg/rules/.... (other class files)

inside the main class, validator.java, i have a method which tries to read the files given a directory : com/dceg/rules, and save the filenames within the directory into a hashmap for later use.. but when i package it into a jar file, the line:

cld.getResources(path);

gives me null... where this isnt the case when i was running it on eclispe.. is there any solutions to this problem?

thank you so much!

publicvoid getClasses(String pckgname)throws ClassNotFoundException{

// This will hold a list of directories matching the pckgname. There may be more than one if a package is split over multiple jars/paths

ArrayList<File> directories =new ArrayList<File>();

try{

ClassLoader cld = Thread.currentThread().getContextClassLoader();

if (cld ==null){

logger.error(new ClassNotFoundException("Can't get class loader."));

}

String path = pckgname.replace('.','/');

// Ask for all resources for the path

Enumeration<URL> resources = cld.getResources(path);

while (resources.hasMoreElements()){

directories.add(new File(URLDecoder.decode(resources.nextElement().getPath(),"UTF-8")));

}

}catch (NullPointerException x){

logger.error(new ClassNotFoundException(pckgname +" does not appear to be a valid package (Null pointer exception)"));

}catch (UnsupportedEncodingException encex){

logger.error(new ClassNotFoundException(pckgname +" does not appear to be a valid package (Unsupported encoding)"));

}catch (IOException ioex){

logger.error(new ClassNotFoundException("IOException was thrown when trying to get all resources for " + pckgname));

}

// For every directory identified capture all the .class files

for (File directory : directories){

if (directory.exists()){

// Get the list of the files contained in the package

String[] files = directory.list();

for (String file : files){

// we are only interested in .class files

if (file.endsWith(".class")){

// removes the .class extension

classes.put( file.substring(0, file.length() - 6) , (pckgname +'.' + file.substring(0, file.length() - 6)) );

}

}

}else{

thrownew ClassNotFoundException(pckgname +" (" + directory.getPath() +") does not appear to be a valid package");

}

}

}

Message was edited by:

hamham3001

[4601 byte] By [hamham3001a] at [2007-10-3 2:34:45]
# 1
A package name is a directory, and a directory isn't regarded as a resource - it has to be an actual "file" or jar entry.
malcolmmca at 2007-7-14 19:33:43 > top of Java-index,Java Essentials,Java Programming...
# 2
oh... then what can i use to read a directory?
hamham3001a at 2007-7-14 19:33:43 > top of Java-index,Java Essentials,Java Programming...
# 3
java.util.jar.JarFileBut you'll have to filter for yourself, I don't thing jars really have directories - just names with slashes in them.p.s. It's generally a bad sign when people try to get directory listing involved .class files.
malcolmmca at 2007-7-14 19:33:43 > top of Java-index,Java Essentials,Java Programming...