Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Java编程设置类路径文件_Java_Eclipse Plugin_Eclipse Classpath - Fatal编程技术网

通过Java编程设置类路径文件

通过Java编程设置类路径文件,java,eclipse-plugin,eclipse-classpath,Java,Eclipse Plugin,Eclipse Classpath,我想在现有java项目的.classpath文件中设置元素的路径和属性值。 i、 我有一个eclipse插件需要这个路径,如果现有路径不正确,我想修复它 例如,我想替换元素: <classpathentry kind="lib" path="C:/foo.jar"> <attributes> <attribute name="javadoc_location" value="file:C:\Javadoc\"/> </attribut

我想在现有java项目的
.classpath
文件中设置
元素的路径和属性值。 i、 我有一个eclipse插件需要这个路径,如果现有路径不正确,我想修复它

例如,我想替换元素:

<classpathentry kind="lib" path="C:/foo.jar">
   <attributes>
    <attribute name="javadoc_location" value="file:C:\Javadoc\"/>
   </attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/ProgramsFiles/foo.jar">
   <attributes>
    <attribute name="javadoc_location" value="file:C:\ProgramsFiles\Javadoc\"/>
   </attributes>
</classpathentry>
如何替换.classpath文件中的现有路径?

读取。您不能/不应该修改现有条目,而是替换它们

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();
....
}