I am trying to instantiate the Reflections class (org.reflections.Reflections) when I run my Jar. I build my project using Maven:
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
</dependency>
When I run the application from within IntelliJ it just works. However, on my collegues computer it doesn't, and it doesn't work when I run the Jar created by Maven. My computer gives the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/reflections/Reflections
at nl.yacht.lakesideresort.controller.CommandLineInterpreter.loadGuiClasses(CommanLineInterpreter.java:30)
at nl.yacht.lakesideresort.controller.CommandLineInterpreter.<init>(CommandLineInterpreter.java:25)
at nl.yacht.lakesideresort.Main.main(Main.java:12) Caused by: java.lang.ClassNotFoundException: org.reflections.Reflections
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
The code I'm trying to run is:
Reflections reflections = new Reflections(ClasspathHelper.forPackage("nl.yacht.lakesideresort.controller.gui"));
Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Gui.class);
for(Class<?> kl : annotated){
Gui gui = kl.getAnnotation(Gui.class);
String name = gui.name().toUpperCase();
try {
map.put(name, (Command) kl.newInstance());
} catch (Exception e) {
System.out.println("Couldn't load class " + name);
}
}
Even if I comment out everything underneath the Reflections reflections = new ... line I will get the exception.
Why can't I instantiate the Reflections class in the Jar?
Aucun commentaire:
Enregistrer un commentaire