3

I want to set the path and the attribute's value of <classpathentry> element in .classpath file of an existing java project. i.e. I have an eclipse plugin that need this path, and I want to fix it if the existing path is incorrect.

for example, I want to replace the element:

<classpathentry kind="lib" path="C:/foo.jar">
   <attributes>
    <attribute name="javadoc_location" value="file:C:\Javadoc\"/>
   </attributes>
</classpathentry>

with the element:

<classpathentry kind="lib" path="C:/ProgramsFiles/foo.jar">
   <attributes>
    <attribute name="javadoc_location" value="file:C:\ProgramsFiles\Javadoc\"/>
   </attributes>
</classpathentry>

For now I'm using with the following code to found the entry path:

IJavaProject jProj = (IJavaProject) _Nature.getProject().getNature(JavaCore.NATURE_ID);
IClasspathEntry[] existingEntries = jProj.getRawClasspath();
// iterate over the class path
for (IClasspathEntry entry : existingEntries)
{
String entryStr = entry.getPath().toString();
....
}

how can I replace the existing path in the .classpath file?

user3114639
  • 1,895
  • 16
  • 42

1 Answers1

0

Read http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Fguide%2Fjdt_api_classpath.htm. You can't/shouldn't modify existing entries--replace them, instead.

nitind
  • 19,089
  • 4
  • 34
  • 43