I have a .classpath file of a project which contains all classpath entries. Now it has following entry-
Now, from this entry , I want to find all jars which are associated with this library through java code programatically ? Is there any way to read all jars?
解决方案
The following was investigated running Eclipse JEE Kepler while reading source code that was checked out summer 2016 and debugging Eclipse on startup.
In your workspace root folder there is a file .metadata.plugins\org.eclipse.jdt.core\variablesAndContainers.dat.
This file is read by JavaModelManager from the method loadVariablesAndContainers.
Within variablesAndContainers.dat, I believe there is an entry for each project, and each project has a container. You can see the container name as a String in the file.
Flow continues to
JavaModelManager$VariablesAndContainersLoadHelper.loadContainers(IJavaProject)
From here, the file reads a count of the number of classpath entries. For each entry, it then reads the container with the method VariablesAndContainersLoadHelper.loadClasspathEntry. This creates an array of classpath entries which represents the Java container. This is held in memory as JavaModelManager.PersistedClasspathContainer.
This is what you are looking for if creating a standalone application.
If creating an Eclipse plugin, examine the behavior of JavaModelManager.getClasspathContainer.
You'll have to study the code, and maybe debug a lot of Eclipse startups to figure out the whole format of the file.