简体   繁体   中英

Iterating classes in build_path of eclipse project

Is it possible to access all classes in build_path of eclipse java project?

I am developing eclipse plugin that should contribute new popup menu item, right clicking on an project in navigator view,
i want to be able to execute some logic that involves reflection, for that I need an ability to iterate over all classes/jars in the build path of that project.

So, again, how can I obtain the build_path classes?

This is a rather broad question with a lot of code required, so I am only going to cover some of the basics.

Assuming you have the IProject for the project you can get the IJavaProject object you need using:

IProject project = ....

IJavaProject javaProject = JavaCore.create(project);

You can then get the class path entries for the objects in the build path with:

IClasspathEntry [] entries = javaProject.getResolvedClasspath(false);

This gives you an array of entries with any variables resolved.

You will have to look at each entry in this list. The entry can be one of several different kinds.

entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY

The entry is a jar or folder library which may be in the workspace (relative path) or external to the workspace (absolute path).

entry.getEntryKind() == IClasspathEntry.CPE_PROJECT

The entry is another project. You will have to resolve the path for that project as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM