lazyboy
lazyboy

Reputation: 311

Java Classpath in context

I'm writing a program, which needs to known all classes/jars in its context. For example if it runs in a Maven environment, it must know the path to all of the dependent jars in .m2/. If it runs in Tomcat, it must know the jars in WEB-INF/lib/. It should do this automatically, without any configuration. I have used System.getProperty("java.class.path") but it does not work in Tomcat.

Upvotes: 1

Views: 532

Answers (1)

Ayub Malik
Ayub Malik

Reputation: 2568

I think a similar question has been asked before. You will need to get the JARs loaded from the SystemClassLoader.

((URLClassLoader) (Thread.currentThread().getContextClassLoader())).getURLs()

See this link for further details.

How to get classpath from classloader?

Upvotes: 1

Related Questions