Eclipse workspace: Do I put my images in the 'src' or 'bin' folder?

I am working on a project in Java, and sometimes all my images accidentally disappear from the bin folder of the project. This becomes very annoying because I have to put everything in every time every time this happens. Someone told me that I should not put my extra files in the trash, but in src. But eclipse does not read my images if I put them in src, as if they were not there. Why is this happening? Thank.

+5
source share
7 answers

Create one resourcesfolder and put there. Then mark this folder as the “source folder” (right-click → Build path → Use as source folder)

+9
source

Follow these two steps. Worked well for me at Eclipse Kepler.

  • Bring an image or other resource files to a Java project

    I am. Mouse right-click on your Java-project and run: New -> Source Folder. In this example, I call my "res" folder.

    II. Go to the file browser and you will see this "res" folder in the root folder of the Java project. Now copy or move the image and other resource files into it.

    III. Eclipse "res" : Refresh. .

    IV. , , "bin" .

  • (, JFrame, this ) "/" :

    Image img = new ImageIcon(this.getClass().getResource("/MyImage.gif")).getImage();
    

: . "bin" . , , "Runnable Jar File", , jar.

+11

bin - , .

Class.getResource() ClassLoader.getResource() ( API-), , src , . .

docs :

, , , Java > p > , . , , .

, "", , . bin , .

, - , src, .

+6

, "res", . , "Img". .

0

. "bin" "src" :

Image image2 = new Image(getClass().getResourceAsStream("IMAGES/Main-icon.png"));

0

Maven maven install.

0

All Articles