Pessoal,
Novamente naquele problema do Reflection, estava tentando recuperar as classes de um pacote específico, e encontrei uma funcionalidade semelhante na internet e dei uma adaptada pra minha necessidade, o problema é que em uma classe independente "desktop" que não tem nada haver com o websphere ela funciona perfeitamente, porém qdo eu adiciono essa funcionalidade no websphere de alguma forma a Classe URL se perde e não conegue recuperar o diretório correto referente aquele resource.
Segue o código para ficar mais claro:
public static ArrayList listClasses(String pckgname) throws Exception {
// Code from Conrad Peres
// ======
// Translate the package name into an absolute path
ArrayList nameofClasses = new ArrayList();
try {
String name = new String(pckgname);
String names[] = { "" };
if (!name.startsWith("/")) {
name = "/" + name;
}
// Code from Conrad Peres
// ======
// Translate the package name into an absolute path
ArrayList nameofClasses = new ArrayList();
try {
String name = new String(pckgname);
String names[] = { "" };
if (!name.startsWith("/")) {
name = "/" + name;
}
name = name.replace('.', '/');
// Get a File object for the package
URL wrl = Launcher.class.getResource(name);
File directory = new File(wrl.getFile());
// New code
// ======
if (directory.exists()) {
// Get the list of the files contained in the package
String[] files = directory.list();
for (int i = 0; i < files.length; i++) {
URL wrl = Launcher.class.getResource(name);
File directory = new File(wrl.getFile());
// New code
// ======
if (directory.exists()) {
// Get the list of the files contained in the package
String[] files = directory.list();
for (int i = 0; i < files.length; i++) {
// we are only interested in .class
files
if (files[i].endsWith(".java")) {
// removes the .java extension
String classname = files[i].substring(0, files[i]
.length() - 5);
try {
// Try to create an instance of the object
Object o = Class
.forName(pckgname + "." + classname)
.newInstance();
nameofClasses.add(classname);
if (o instanceof Command) {
System.out.println(classname);
}
} catch (ClassNotFoundException cnfex) {
System.err.println(cnfex);
throw new ClassNotFoundException();
} catch (InstantiationException iex) {
iex.getMessage();
throw new InstantiationException();
// We try to instantiate an interface
// or an object that does not have a
// default constructor
} catch (IllegalAccessException iaex) {
System.out.println("The class is not public");
iaex.getMessage();
throw new InstantiationException();
// The class is not public
}
}
if (files[i].endsWith(".java")) {
// removes the .java extension
String classname = files[i].substring(0, files[i]
.length() - 5);
try {
// Try to create an instance of the object
Object o = Class
.forName(pckgname + "." + classname)
.newInstance();
nameofClasses.add(classname);
if (o instanceof Command) {
System.out.println(classname);
}
} catch (ClassNotFoundException cnfex) {
System.err.println(cnfex);
throw new ClassNotFoundException();
} catch (InstantiationException iex) {
iex.getMessage();
throw new InstantiationException();
// We try to instantiate an interface
// or an object that does not have a
// default constructor
} catch (IllegalAccessException iaex) {
System.out.println("The class is not public");
iaex.getMessage();
throw new InstantiationException();
// The class is not public
}
}
}
}
} catch (NullPointerException iaex) {
System.out.println("NullPointerException:" + iaex.getMessage());
iaex.printStackTrace();
// The class is not public
}
return nameofClasses;
}
} catch (NullPointerException iaex) {
System.out.println("NullPointerException:" + iaex.getMessage());
iaex.printStackTrace();
// The class is not public
}
return nameofClasses;
}
Espero que alguém já tenha passado por algo do gênero.
Aguardo Resposta
Att
Conrad Peres.
Yahoo! doce lar. Faça do Yahoo! sua homepage.
YAHOO! GROUPS LINKS
- Visit your group "jug-petropolis" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
