开发者

Java resources after export project

开发者 https://www.devze.com 2023-04-12 02:19 出处:网络
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\"),

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开发者_Python百科

Thanks


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号