When I export my code as runnable JAR from eclipse all the files that I've set it to grab such as button images and other files are missing even though they are actually in the JAR. I've added getClass().getResource
in front of the files but then when I try to run the JAR nothing even happens, any suggestions?
Seems like you not putting your stuff in the right sense. In order to make it work, follow these steps :
Project
in Project Explorer Tree
.New -> Source Folder
and then provide any Name
to the Source Folder
.Source Folder
so created by you, like if you want to add images then make a New Folder
, by manually visiting this Source Folder
through File System
.New Folder
as images
and copy your images to this Folder
.Refresh
your Project
from the Project Explorer, by Right Clicking your Project, here you be able to see your added content now after refreshing.Now in order to access, say any image, you will use.
getClass().getResource("/images/yourImageName.extension");
which will return one URL object. Do remember the first forward slash
, in this case, since whatever is inside your Source Folder is accessed with the help of this, in simpler terms. Now when you will Run your project, the content of this Source Folder will be automatically added to the bin folder and when you will create a Runnable Jar, then the stuff inside your Source Folder can be accessed as it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With