I am trying to use Reflections in my Java project (also using Spring boot), and I have to get all the classes of a package that implements an interface.
public static Object[] getClasses(String packageName) throws IOException
{
Reflections r = new Reflections(packageName);
Set<Class<? extends EntityXML>> allClasses = r.getSubTypesOf(EntityXML.class);
return (Object[]) allClasses.toArray();
}
But it returns me always this error.
java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator;
at org.reflections.Reflections.expandSuperTypes(Reflections.java:380)
at org.reflections.Reflections.<init>(Reflections.java:126)
at org.reflections.Reflections.<init>(Reflections.java:168)
at org.reflections.Reflections.<init>(Reflections.java:141)
at gcs.fds.focus.lib.utils.FindPackages.getClasses(FindPackages.java:14)
...
I try to import the google.guava package to avoid this error, and it fix it, but I would like not to import it, because it is a package without use in my project.
Any idea about how to avoid this error?
Okey I solved!
I deleted the google.guava dependency, and I make a
mvn dependency:tree
where I could see that other of my dependencies imports also google.guava, but version 19 which I read that makes this conflict. (everit.json dependency), so I exclude the google.guava from this dependency and it works!
<dependency>
<groupId>org.everit.json</groupId>
<artifactId>org.everit.json.schema</artifactId>
<version>1.3.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>