Java - Eclipse 上的类路径问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2520821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java - Problem with the classpath on Eclipse
提问by Amokrane Chentir
I'm trying to recompile a project I've been working on and I keep getting an error message when trying to load a property file:
我正在尝试重新编译我一直在处理的项目,但在尝试加载属性文件时不断收到错误消息:
The system cannot find the path specified.
I guess this has to do with the classpath. But I've added the path to the file in Properties-> Java build path-> Libraries (external class). I also checked the .classpath file generated by eclipse, and the path is really there!
我想这与类路径有关。但是我已经在属性-> Java 构建路径-> 库(外部类)中添加了文件的路径。我也查了一下eclipse生成的.classpath文件,路径真的有!
Why isn't Eclipse looking at the right path?
为什么 Eclipse 不寻找正确的道路?
采纳答案by DJ.
There 2 different classpaths, build classpath and runtime classpath. The one you are setting is the build classpath.
有 2 个不同的类路径,构建类路径和运行时类路径。您正在设置的是构建类路径。
Check your runtime classpath by going to Run -> Run Configurations
and select your application configuration. Check the classpath setting there.
通过转到Run -> Run Configurations
并选择您的应用程序配置来检查您的运行时类路径。检查那里的类路径设置。
There is another workaround for this also. Eclipse by default will include your output folder(usually named bin) in your classpath. Typically anything that are not compilable in srcfolder will be copied to binas is. I assumed your property file is not located in srcfolder. What you can do is to open your project property and add the folder where your property is located into Java Buld Path -> Source (tab)
. This way eclipse will copy the content of that folder into binand will be in the classpath.
还有另一种解决方法。默认情况下,Eclipse 将在您的类路径中包含您的输出文件夹(通常名为bin)。通常,src文件夹中不可编译的任何内容都将按原样复制到bin。我假设您的属性文件不在src文件夹中。您可以做的是打开您的项目属性并将您的属性所在的文件夹添加到Java Buld Path -> Source (tab)
. 这样 eclipse 会将该文件夹的内容复制到bin 中,并将位于类路径中。
回答by Thorbj?rn Ravn Andersen
There are several ways to read a property file:
有几种方法可以读取属性文件:
Have it in the current working directory (the one cd'ed to). You can do this in the Eclipse launch configuration. (Run -> Run...)
Include it in your application, by having it in a source folder. You then need to read it in through a class loader to be able to get it always (when jarred up, through Java Web Start, etc).
将它放在当前工作目录中(cd 到的那个)。您可以在 Eclipse 启动配置中执行此操作。(运行 -> 运行...)
通过将其放在源文件夹中,将其包含在您的应用程序中。然后,您需要通过类加载器读取它,以便能够始终获取它(当遇到问题时,通过 Java Web Start 等)。
回答by Kusuma Seshavarapu
Double check if the property file or its directory is in the excluded list of the project Source. If it is remove the exclusion filter and try recompiling.
仔细检查属性文件或其目录是否在项目源的排除列表中。如果是删除排除过滤器并尝试重新编译。