I have a maven project. And i want to iterate through its dependency jar projects and read some property files in them. With eclipse resource api, i can get an IProject instance in workspace and access its classpath file.
Class-path has the following structure.
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
How can i extract the actual dependency jar locations from this?
i was expecting something like this instead
<classpath>
<classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar"/>
<classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.9.1/xml-apis-2.9.1.jar"/>
</classpath>
2.Or is there any better approach than this to read through maven dependency jars programatically?
The getResolvedClasspath
method of IJavaProject
deals with resolving containers:
IProject project = ... get project
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true);
The JavaDoc says:
This is a helper method returning the resolved classpath for the project as a list of simple (non-variable, non-container) classpath entries. All classpath variable and classpath container entries in the project's raw classpath will be replaced by the simple classpath entries they resolve to.