Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 361
TedTrippin Avatar asked Sep 18 '25 19:09

TedTrippin


1 Answers

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

like image 96
Evgeniy Dorofeev Avatar answered Sep 21 '25 10:09

Evgeniy Dorofeev