1

So, In my code I have the app take resources from a folder named res/ and in the Manifest.mf file "Class-Path" is set to res/ but it doesn't read the files inside the res/ folder inside the jar, it reads the res/ folder from the folder where the jar file is. (sorry for bad explaining) Example: If I have my jar inside a folder named "Game" the res folder must be inside "Game" for it to work. My question is: How do I make it to read res/ from inside the jar?

I've set the ImageIcons like this:

ImageIcon icon = new ImageIcon("res/image.png");
roboticonx8
  • 39
  • 1
  • 11

1 Answers1

2

Read the javadoc. The constructor you're using is described like this:

public ImageIcon(String filename)

Creates an ImageIcon from the specified file.

So it doesn't use the classpath at all. It just looks for the file res/image.png from the current directory.

Everything in your jar is accessible by the class loader, since the jar is in the classpath. You don't need any manifest entry. But you need to load the image resource using the class loader:

ImageIcon icon = new ImageIcon(MyClass.class.getResource("/res/image.png"));
JB Nizet
  • 633,450
  • 80
  • 1,108
  • 1,174