Netbeans: Bitmaps, Jars and Manifests.

Started by
2 comments, last by Anri 8 years, 7 months ago

Hello there. I seem to be having trouble including a bitmap file in my project's JAR file, using Netbeans.

The actual Netbeans project I have called "GraphicsStuff", and I have written my own loader to load in Bitmap files and have successfully displayed the image in a window. Now, I've loaded in the bitmap as a resource instead of as a file, and when I test the application in Netbeans it seems to work. So far so good.

Here is where the problem rears its ugly head! After I clean and build the project, I then try to run the jar file outside of Netbeans, and whilst I can get the window to display, it does not display the bitmap image. In the Linux terminal, I get the following message...

Error: Failed to load the file: java.io.FileNotFoundException: file:/home/steven/Desktop/JavaStuff/GraphicsStuff/dist/GraphicsStuff.jar!/data/title.bmp (No such file or directory)

...which is really odd. I have included the bitmap file in its own folder in the Source packages drop-down list in the Projects tab viewer, in Netbeans. Which is great because I can open the JAR itself and see that there is indeed a folder called "data" and it contains my bitmap file. So, I know the bitmap IS in the JAR. However, looking inside the Manifest.MF file thats inside the JAR file, this is the contents...

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_31-b13 (Oracle Corporation)
Class-Path:
X-COMMENT: Main-Class will be added automatically by build
Main-Class: graphicsstuff.GraphicsStuff



...is it me or shouldn't there be something like "data/image.bmp" in there somewhere? From what I can tell, the bitmap file is inside the JAR, but the manifest doesn't know about it. Have I missed an important step here where Netbeans is concerned?

Cheers.

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

Advertisement

A few common mistakes, please check if you have any:

  1. Check that you are using getResourceAsStream() instead of .getResource(). The first one assumes that resource is placed on classpath (which should be if you created the data folder as a source folder) the other is just generic/absolute path resource load. This is the most common mistake!
  2. Check that you are loading the file by prefixing the file name with "/": myCustomLoader.load(this.getrClass().getResourceAsStream("/title.bmp") (notice the "/" and no folder name ).

Hope it helps smile.png

Br, b.

Guilty on both accounts!

If the Manifest file is fine as it is, I guess I just need to go back to the drawing board regarding my bitmap loader code. Its a challenge in itself, but at least I know what needs to be done now.

Many thanks Busho!

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

Just a quick update to say I've managed to load the bitmap as a resource and can access it via the jar outside of Netbeans! The result is rather odd: a black window with a little bit of the image showing just at the bottom of the window. Something I need to spend time fixing(and I'm sure I can), but I know that its at least reading in from the bitmap within the JAR.

Once again - thank you so much Busho!

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

This topic is closed to new replies.

Advertisement