Avatar billede fredand Forsker
20. maj 2004 - 13:10 Der er 2 kommentarer og
1 løsning

Read Images from a executable Jar

Hello!

I have created a executable jar with a my classes and my folder with images for my app.
jar-file:
meta
classes
images/(my images)

I thought that the app would get the images included in the jar as the class files when it executes. But I have realized that it tries to read from a folder in the folder it executes. So I have to create a folder beside the jar-file with the images.

So now is my question is it possible to read from the jar-file and get all resources from that so I do not need to create any other folders?

Best regards
Fredrik
Avatar billede _carsten Nybegynder
20. maj 2004 - 13:17 #1
This should do it
getClass().getResource("/FolderWithImages/filename.ext")

example:
new javax.swing.ImageIcon(getClass().getResource("/FolderWithImages/filename.ext"));
Avatar billede fredand Forsker
30. december 2006 - 13:12 #2
You solved it!
Thanks!
Please give svar so I can reward you!!
Avatar billede _carsten Nybegynder
30. december 2006 - 15:57 #3
:)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester