I got two jar files, lets call them domain.jar
and scanner.jar
. In the scanner jar I have used Reflections library like so:
Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(ClasspathHelper.forPackage(packageName)).setScanners(new SubTypesScanner(false)));
Set<Class<?>> subTypesOf = reflections.getSubTypesOf(Object.class);
where if I point the packageName
to packages inside the scanner.jar everything works fine, but if I try to find classes from the domain.jar
it always returns empty set.
I run it with java -cp domain.jar -jar scanner.jar
Any idea what I'm doing wrong? From Reflections usage examples it supports multimodule projects so this should be possible.
The -cp
and -jar
options are mutually exclusive. Either you use -jar
, and the classpath is composed from the jar file and all the other jar files referenced in its manefest, or you use -cp
and list all the jars that must be part of the classpath.
The documentation about the -jar option says:
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
So, try with
java -cp domain.jar;scanner.jar your.fully.qualified.MainClass