TedTrippin
TedTrippin

Reputation: 3662

How to get src/main/java classloader from unit test

In a unit test, I'm trying to get a list of classes under a package.

When I do

...getClassLoader().getResource("<some package in both main and test>");

from a unit test, it returns a URL that points to test-classes. How do I get the URL to the main classes?

EDIT:

To be clearer, I am after a classloader that gives me access to the main classes. Ultimately, to get the right URL.

Upvotes: 4

Views: 1518

Answers (1)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136062

ClassLoader.getResource returns the first URL it found. Try getResources() it will search on all available classpathes

Upvotes: 5

Related Questions