在Eclipse中调试Java时,如何使getResourceAsStream工作? [英] how do you make getResourceAsStream work while debugging Java in Eclipse?

查看:471
本文介绍了在Eclipse中调试Java时,如何使getResourceAsStream工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是令人难以置信的...当我在包含文本文件的打包JAR文件上运行Java时,我可以使getResource()和getResourceAsStream()正常工作。 (有关参考,请参阅访问资源)即使我将文本文件放在与我编译的.class文件相同的树中,我似乎无法使相同的程序在Eclipse中正常运行。



你们中有一个可以指出我的任何细节,以确保getResource()和getResourceAsStream()函数正常工作?



我有一个预感与CLASSPATH和/或Eclipse放置.class文件进行自动编译。 (我注意到,当我运行Ant时,它会编译自我上一次Ant构建以来发生的所有Java文件,即使Eclipse已经编译了这些Java文件。)

解决方案

如果将文本文件与源文件一起放在一起,Eclipse将会将其复制到其编译的.class文件的任何位置,因此当您运行来自Eclipse的应用程序(您也可以在Eclipse中编辑文件)。


This is mind-boggling... I can make getResource() and getResourceAsStream() work properly when I run Java on my packaged JAR file that includes a text file. (for reference see the Sun docs on accessing resources) I can't seem to make the same program work properly when I am running it within Eclipse, even though I've placed my text file in the same tree as my compiled .class files

Can one of you point me at any subtleties to ensure that getResource() and getResourceAsStream() functions work properly?

I have a hunch it has to do with CLASSPATH and/or where Eclipse puts the .class files it autocompiles. (I've noticed when I run Ant, it compiles all the Java files that have changed since my last Ant build, even though Eclipse has compiled those Java files already.)

解决方案

If you put your text file along with your source files, Eclipse will copy it to wherever it's placing its compiled .class files, and so you'll see your text file when you run your app from Eclipse (and you will be able to edit the file from within Eclipse as well).

这篇关于在Eclipse中调试Java时,如何使getResourceAsStream工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆