我在 ear
中打包的瘦 war
中遇到了类加载问题。
这里还封装了其他的ejb模块。有些可以通过 spring 加载,有些则不能。
想象一下以下场景:
someApp.ear
|- someEJBs1.jar
|- someEJBs2.jar
...
|- someEJBsX.jar
|- someWar.war
如果我尝试从 someWar.war 通过 spring 访问以下位置的一些类:
- someEJBs1.jar 它可以工作
- 但是对于 someEJBs2.jar 中的那些,我收到
java.lang.ClassNotFoundException
。
不知道问题出在哪里。
我的 MANIFEST.MF
根本不包含任何类路径信息。
我已经在想是否有任何方法可以在运行时(也许在调试期间)查看加载的类,或者可能为特定 war 文件提供的类路径?
我正在 glassfish 3.1.1 中运行(这是一项要求,不可能对此进行任何更改)。
最佳答案
在代码中尝试以下调试功能:
//Prints the Root directory
public static void printPWD() {
File dir1 = new File(".");
try {
System.out.println("Current dir : " + dir1.getCanonicalPath());
dir1 = null;
} catch (Exception e2) {
e2.printStackTrace();
}
}
// Prints all files on the ClassPath to the system.out
public static void printClasspathFiles() {
ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();
// Get the URLs
URL[] urls = ((URLClassLoader) sysClassLoader).getURLs();
for (int i = 0; i < urls.length; i++) {
System.out.println(urls[i].getFile());
}
}
//prints the classpath to system.out
print printClasspath(){
System.out.println(System.getProperty("java.class.path"));
}
要获取所有已加载的类,getAllLoadedClasses 方法将很有用。 See Here
关于java - 瘦 war 的 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14342107/