Hugo Alves
Hugo Alves

Reputation: 188

Java resources after export project

I've done a java aplication that have some images as resources like this:

->src ->resources ->images

For accessing this resources i've used getClass().getResource("/resources/images/img.jpg"), this works fine when i am on eclipse, but when i export the project to a jar the path change to something this genre: "jar:C:/path/deployed.jar!/resources/images/img.jpg".

What i am doing wrong? It is possible to export all the project in one jar?

One more question, this resources include a derby db that dont work either when deployed in jar file

Thanks

Upvotes: 0

Views: 257

Answers (2)

MaDa
MaDa

Reputation: 10762

One more question, this resources include a derby db that dont work either when deployed in jar file

As Hovercraft stated, Derby DB (meaning the data files, not implementation) won't start from a jar. And it doesn't matter you don't insert anything, Derby needs to open these files for writing. They need to be in a directory where you have writing access.

Upvotes: 0

MBU
MBU

Reputation: 5098

Try using getResourceAsStream() instead of getResource() to access resources in your jar file.

Upvotes: 2

Related Questions