Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

image not load in jar  RSS feed

 
Gospodin Dzon
Greenhorn
Posts: 2
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

i'm trying to load image in my project. i'm using netbeans and while project is run from netbeans everything is working fine. after packing project to jar file when run there is no image, just a background and image loads null. can somebody please help me to fix this code? i have tried to load image many different ways but still the same. here is the code:

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the image is packed in the JAR file, then it doesn't exist as a file itself, so you can't really use the methods you do when you run an unpacked version of the application. What you need is to find the Path of the image file as it sits inside the JAR. You normally do this through the ClassLoader. Let's say for example that your JAR file is packed like this:

Jabacina.jar!/ <- root of the jar file
Jabacina.jar!/images/image.png <- image of interest
Jabacina.jar!/jabacina/jabacina.class <- class file in package
Jabacina.jar!/META-INF/MANIFEST.MF <- Manifest file

Then you could do something like
 
Gospodin Dzon
Greenhorn
Posts: 2
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you, my friend. it works now. i have tried using ClassLoader but it seems i havent used it right way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!