Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getClass().getResource("...") does not work.

843806Feb 19 2008 — edited Feb 19 2008
In a swing application I try to access resources such as a dictionary: "english.0" using getClass().getResource("/dict/english.0").

Ex:
File dictFile = new File(getClass().getResource("/dict/english.0").toURI());
File phonetFile = new File(getClass().getResource("/dict/phonet.en").toURI());

SpellDictionary dictionary = new SpellDictionaryHashMap(dictFile, phonetFile);
// continue doing other operations with dictionary...

This works fine as long as I am running the application locally in the IDE (netbeans 6.0) but when I distribute my application using a jar file it doesn't work.

dictFile.getPath() is returning
C:\Documents and Settings\gymartin\UnitTestManager\build\classes\dict\english.0. This should be a relative NOT Absolute Path right? Users using the jar file don't have this path in their PC, and I think that's the reason why it's not working. How can I fix this problem?

I appreciate your help guys!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2008
Added on Feb 19 2008
2 comments
215 views