由 java 编译器指示诊断 "incorrect classpath"
Diagnose "incorrect classpath" indicated by java compiler
出于对 lack of ideas 的绝望,我目前正在研究一种从 eclipse 插件内部编译单个文件的方法。
到目前为止,我已经成功编写了编译单个 .java 文件的代码,该文件没有外部 .class
(不在 .jar
内部)依赖项。
对于编译过程,我知道所有依赖项 .class
文件的位置,并且我使用 -classpath
选项将该信息提供给编译器。
目前,我这样调用编译器:
String[] params = new String[]{
"-properties", propertiesFile,
"-g", "-preserveAllLocals",
"-classpath", classPath,
fileToCompile,
"-d", outputPath,
"-proc:none",
"-proceedOnError",
};
boolean result = BatchCompiler.compile(
params, new PrintWriter(outWriter), new PrintWriter(errWriter), null);
变量:
- propertiesFile: 存在,它包含工作区 + 项目设置的合并,没有重复(按此顺序)。
- classPath: 包含多个路径,用“;”分隔(这个有问题,见下文)
- fileToCompile包含我要编译的文件的绝对路径。请注意,此文件 不在 源目录中。
- outputPath:项目"bin"所在目录。它从 IProject 对象本身获取它。
你可能会发现其他选项的意思here。
classPath
给我一个错误。此测试项目中存在两个 类:
这是它的内容(在通过从原生 java:
中删除大部分 .jar 包含来减小大小之后
"C:/Program Files (x86)/java/jre1.8.0_66/lib/resources.jar";"C:/Program Files (x86)/Java/jre1.8.0_66/lib/rt.jar";D:/Users/user/runtime-EclipseApplication/Tests/bin"
我试过将它们用作类路径中的最后一个 "include":
"D:/Users/user/runtime-EclipseApplication/Tests/bin"
"D\:\Users\user\runtime-EclipseApplication\Tests\bin"
"D\:/Users/user/runtime-EclipseApplication/Tests/bin"
"D\:\Users\user\runtime-EclipseApplication\Tests\bin"
这是它在 stderr 中给出的输出:
incorrect classpath: "D:/Users/user/runtime-EclipseApplication/Tests/bin"
----------
1. ERROR in D:\Users\user\runtime-EclipseApplication\.metadata\.plugins\myplugin\tmp\sources\Test2.java (at line 3)
public class Test2 extends Test{
^^^^^^^^
Test cannot be resolved to a type
我可以在自己的代码中断言,就在调用编译器之前:
- 该类路径目录存在
- 那个Test.class在那个目录里
- 我在代码执行时使用默认包
我在这里做错了什么?为什么它在错误的类路径中对其进行分类?
我正在使用 org.eclipse.jdt.core(v.3.10.2) 依赖项,我正在 eclipse Luna (4.4) 中编译,这是我希望我的插件支持的最低版本。
经过这几天,不知何故......
"C:/Program Files (x86)/java/jre1.8.0_66/lib/resources.jar";"C:/Program Files (x86)/Java/jre1.8.0_66/lib/rt.jar";D:/Users/user/runtime-EclipseApplication/Tests/bin
<- 没有结尾引号
那奏效了。我不记得我是否做了其他任何事情,但无论是否有空格,它都是这样工作的。
我仍然想知道是什么导致使用引号的第一个元素之间不一致,但我的元素不能使用任何引号。
出于对 lack of ideas 的绝望,我目前正在研究一种从 eclipse 插件内部编译单个文件的方法。
到目前为止,我已经成功编写了编译单个 .java 文件的代码,该文件没有外部 .class
(不在 .jar
内部)依赖项。
对于编译过程,我知道所有依赖项 .class
文件的位置,并且我使用 -classpath
选项将该信息提供给编译器。
目前,我这样调用编译器:
String[] params = new String[]{
"-properties", propertiesFile,
"-g", "-preserveAllLocals",
"-classpath", classPath,
fileToCompile,
"-d", outputPath,
"-proc:none",
"-proceedOnError",
};
boolean result = BatchCompiler.compile(
params, new PrintWriter(outWriter), new PrintWriter(errWriter), null);
变量:
- propertiesFile: 存在,它包含工作区 + 项目设置的合并,没有重复(按此顺序)。
- classPath: 包含多个路径,用“;”分隔(这个有问题,见下文)
- fileToCompile包含我要编译的文件的绝对路径。请注意,此文件 不在 源目录中。
- outputPath:项目"bin"所在目录。它从 IProject 对象本身获取它。
你可能会发现其他选项的意思here。
classPath
给我一个错误。此测试项目中存在两个 类:
这是它的内容(在通过从原生 java:
"C:/Program Files (x86)/java/jre1.8.0_66/lib/resources.jar";"C:/Program Files (x86)/Java/jre1.8.0_66/lib/rt.jar";D:/Users/user/runtime-EclipseApplication/Tests/bin"
我试过将它们用作类路径中的最后一个 "include":
"D:/Users/user/runtime-EclipseApplication/Tests/bin"
"D\:\Users\user\runtime-EclipseApplication\Tests\bin"
"D\:/Users/user/runtime-EclipseApplication/Tests/bin"
"D\:\Users\user\runtime-EclipseApplication\Tests\bin"
这是它在 stderr 中给出的输出:
incorrect classpath: "D:/Users/user/runtime-EclipseApplication/Tests/bin"
----------
1. ERROR in D:\Users\user\runtime-EclipseApplication\.metadata\.plugins\myplugin\tmp\sources\Test2.java (at line 3)
public class Test2 extends Test{
^^^^^^^^
Test cannot be resolved to a type
我可以在自己的代码中断言,就在调用编译器之前:
- 该类路径目录存在
- 那个Test.class在那个目录里
- 我在代码执行时使用默认包
我在这里做错了什么?为什么它在错误的类路径中对其进行分类?
我正在使用 org.eclipse.jdt.core(v.3.10.2) 依赖项,我正在 eclipse Luna (4.4) 中编译,这是我希望我的插件支持的最低版本。
经过这几天,不知何故......
"C:/Program Files (x86)/java/jre1.8.0_66/lib/resources.jar";"C:/Program Files (x86)/Java/jre1.8.0_66/lib/rt.jar";D:/Users/user/runtime-EclipseApplication/Tests/bin
<- 没有结尾引号
那奏效了。我不记得我是否做了其他任何事情,但无论是否有空格,它都是这样工作的。
我仍然想知道是什么导致使用引号的第一个元素之间不一致,但我的元素不能使用任何引号。