Eclipse项目添加jar文件相对路径

当从属性-Java Build Path添加jar文件的时候, 实际添加的是jar文件的绝对路径. 当移动了工作空间的所在目录, 这些jar 依赖就会丢失.

:jars and class folders on the build path are missing

解决办法是直接编辑项目根目录下的.classpath文件, 格式是常见的XML. 修改path属性为相对路径. 如下

 
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path=""/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="lib" path="./cpdetector_1.0.10.jar"/>
    <classpathentry kind="lib" path="./ext/antlr-2.7.4.jar"/>
    <classpathentry kind="lib" path="./ext/chardet-1.0.jar"/>
    <classpathentry kind="lib" path="./ext/jargs-1.0.jar"/>
    <classpathentry kind="lib" path="./jarlib/antlr-runtime-3.1.jar"/>
    <classpathentry kind="lib" path="./jarlib/jStyleParser.jar"/>
    <classpathentry kind="lib" path="./jarlib/junit-4.4.jar"/>
    <classpathentry kind="lib" path="./jarlib/logback-core-0.9.9.jar"/>
    ...
    ...
 

修改保存之后刷新项目即可.