This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting image path correctly under a JAR file  RSS feed

 
Omar Hezi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My very first question.
I created a simple slideshow desktop java program that works perfectly when I run it in the NetBeans environment.
However, after building it, and accessing the jar file using "java -jar", it shows an error.

MY QUESTION: Why is this error showing although the file heirarchy and the path specified are matching?

ERROR:



Method showing error:


Heirarchy:


What I have tried:

using an input stream like:


Removing the backslash before Images" in the path

putting the images folder in the same folder as the main class

Editing the manifest file manually

Not using the "File" Object as I realized it doesn't work in a jar file
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the path: Images/images exist in the jar file?  Does that folder have the images you are trying to load?

You can see the paths by opening the jar file in a zip program.
 
Ron McLeod
Saloon Keeper
Posts: 1600
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We had a discussion on a similar issue in this thread: Runnable JAR won't recognize .txt file
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's also well illustrated in this Oracle tutorial: http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html#getresource
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!