Adding a reflection library to an Eclipse project

I am trying to add the Reflections library to my Java Eclipse project to use it for my needs. The problem is that although I added reflections-0.9.9-uberjar.jar to my lib project folder and also to the build path (in fact, it also appears in the "Linked Libraries" section), the builder does not seem to recognizes it, so this line, for example, gives me an error:

Reflections reflections = new Reflections("net.iberdroid.gameserver.cmds"); "Reflections cannot be resolved to a type" 

If I try to import org.reflections, it says that it cannot be resolved.

Any ideas?

Thank you very much in advance,

+4
source share
2 answers

Quick and dirty way: open reflections-0.9.9-uberjar.jar and extract all the jars into it in the lib folder. Then add these cans to the build path.

A more correct way would be to configure the project as a maven project and configure all the dependencies there. Take a look at the META-INF folder for uberjar.

+6
source

You can import the class:

 import org.reflections.Reflections; 

or all classes in the package:

 import org.reflections.*; 

But you cannot import the package:

 import org.reflections; // looks for a class named "reflections" in the package "org" 

Note that with an IDE like Eclipse, you almost never import anything, because the IDE does this for you. Enter "Refl", then Ctrl-space and Eclipse will suggest using Reflections and add import for you. Or use Reflections without importing it, then press Ctrl-Shift-O, and Eclipse organizes the import, adding all necessary imports and deleting unnecessary ones.

EDIT:

The file reflections-0.9.9-uberjar.jar is not a Java library (cluster containing classes). This is a jar containing other jars (and thus it should be a zip file to avoid confusion). You must unzip the jar and put all the libraries it contains in the build path.

+2
source

All Articles