Java - Eclipse 上的类路径问题
我正在尝试重新编译我一直在处理的项目,并且在尝试加载属性文件时不断收到错误消息:
The system cannot find the path specified.
我想这与类路径有关。但我已经在“属性”->“属性”中添加了文件的路径Java构建路径->图书馆(外部课程)。 我又检查了eclipse生成的.classpath文件,路径确实有!
为什么 Eclipse 没有寻找正确的道路?
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!
Why isn't Eclipse looking at the right path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仔细检查属性文件或其目录是否在项目源的排除列表中。如果是,请删除排除过滤器并尝试重新编译。
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.
有 2 个不同的类路径,构建类路径和运行时类路径。您正在设置的是构建类路径。
通过转到
Run -> 检查您的运行时类路径运行配置
并选择您的应用程序配置。检查那里的类路径设置。对此还有另一种解决方法。默认情况下,Eclipse 将在类路径中包含您的输出文件夹(通常名为bin)。通常,src 文件夹中无法编译的任何内容都将按原样复制到 bin 中。我假设您的属性文件不在 src 文件夹中。你可以做的是打开你的项目属性并将你的属性所在的文件夹添加到
Java Buld Path ->;来源(选项卡)
。这样 Eclipse 就会将该文件夹的内容复制到 bin 中,并且位于类路径中。There 2 different classpaths, build classpath and runtime classpath. The one you are setting is the build classpath.
Check your runtime classpath by going to
Run -> Run Configurations
and select your application configuration. Check the classpath setting there.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 src folder will be copied to bin as is. I assumed your property file is not located in src folder. 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 bin and will be in the classpath.有多种方法可以读取属性文件:
将其放在当前工作目录(cd 到的目录)中。您可以在 Eclipse 启动配置中执行此操作。 (运行 -> 运行...)
通过将其放在源文件夹中将其包含在您的应用程序中。然后,您需要通过类加载器读入它,以便始终能够获取它(当出现冲突时,通过 Java Web Start 等)。
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).