I'm working in a project in Java and sometimes all my images randomly dissapeared from the project's bin folder. It is getting very annoying because I have to put everything again every time it happens. Someone told me that I shouldn't put my extra files in bin but in src. But eclipse doesn't read my images if I put them in src, as if they weren't there. Why is this happening? Thanks.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I had the same problem So I just past image in both folders 'bin' and 'src' in my case I have this code:
run App and its will work
for Eclipse you may just create folder directly in src folder (or in some its package). Then Copy and Paste your image files into created folder. If You need to get proper path till current image just use Class.getResource("yourCreatedFolder/yourImage.someExtension")
Create one
resources
folder and put them there. Then mark that folder as "source folder" (right click -> Build Path -> Use as source folder)Follow these two steps. Worked well for me in Eclipse Kepler.
Bring your image or other resource files into your Java project
i. Mouse right click on your Java project and do:
New -> Source Folder
. In this example, I call my folder "res".ii. Go to your file browser and you should see this "res" folder under your Java project's root folder. Now copy or move your image and other resource files into it.
iii. Now go to Eclipse and right click on this "res" folder and do: Refresh. You should see these files show up in it.
iv. Now build the project and you should see your resource files get copied into the build target "bin" folder.
Now in your class (e.g. your own JFrame class as indicated by the
this
in my sample code below) you can access the resource file and note the leading "/" to indicate file location relative to binary root:Another note: you can use multiple such resource folders to organize your resources. After project build, they all go into the build target root "bin" folder. And of course, you can export your project as "Runnable Jar File", then you can run your application standalone since all resources are automatically packaged into your jar file.
I would convert project to Maven and do maven install.
See if you project has a "res" folder, which stands for resources. If it does, in that folder there should be a "Img" folder. You should put them there.