I’m currently developing a server framework (referred to as A) in Java.
I want to read all the class information of the web application server (referred to as B) using the framework package.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
Enumeration<URL> resources = classLoader.getResources("");
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
retrieveFile(new File(resource.getFile()), "");
if (this.rootPackageName != null) return;
}
} catch (IOException e) {
throw new ComponentScanNotFoundException();
}
I’m trying to analyze the above code and create a singleton instance.
It works fine in IDEs like IntelliJ, but when I create an executable JAR file and try to run it, the return value of resources.hasMoreElements()
is false.
When running in IntelliJ, if I check the classpath of project A, I can see all the package information that project B depends on, but after building the JAR, when I run it with the java -jar command, only project B information is visible. Is this an error caused by incorrect classpath configuration? If not, could you please let me know what the problem is? Thank you.
melchor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.