I'm working in the following setup:
I have a Project A that is used to analyze another maven project B. Project A is added to project B as a dependency and using the exec-maven-plugin I execute the main class of project A inside project B.
Now in this main class I try to load a class from project B using the class loader I got with ClassLoader.getSystemClassLoader();
but I get a ClassNotFoundException
. I also tried the class loader this.getClass().getClassLoader();
but it didn't change anything.
I checked the classpath with mvn -X
and the target directory of the project was added and all compiled classes are actually in there too.
If I try to check the class path from within the code I just get /opt/maven/boot/plexus-classworlds-2.5.2.jar
Figured out the problem.
The right class loader is the one that I get with this.getClass().getClassLoader();
. The main problem was that I tried to load a test class and target/test-classes
was not on the class path.