Jump to content
  • Advertisement
Sign in to follow this  
Dawoodoz

Building jar with resources without IDE

This topic is 539 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have created a manifest file for my desktop Java game that is used to create a jar file automatically from my shell script and now I need to add resources into the jar file.  :)

Is there a simple way to specify a folder in the manifest file without depending on additional tools? All guides point to the obvious way to just point and click in Netbeans but I want to know how the build process works so that I can fix things when they break using only the JDK tools.

Shell script for building the jar:

chmod +x ./compile.sh
./compile.sh
cp ./manifest.txt ./../output
(cd ./../output;
jar cfm Game.jar manifest.txt *
chmod +x ./Game.jar
java -jar Game.jar ./../source/media/
) 

I am currently giving the path of the media folder as a command line argument since it might be useful later for mods.

The manifest only contains the main class name for now and I haven't figured out a good namespace for Main yet.

Main-Class: Main

Share this post


Link to post
Share on other sites
Advertisement

It is a zip file format, it requires a few specific items.  Clicky

At a glance from your description it looks like your manifest file has the wrong name -- MANIFEST.MF instead of manifest.txt -- and it is not in the META-INF directory.

I'm pretty sure they're also case sensitive, all uppercase.  I think (but I'm not absolutely certain) that the jar tool does it automatically, but that's the first place I'd check.

Share this post


Link to post
Share on other sites
chmod +x ./compile.sh
./compile.sh
cp ./MANIFEST.MF ./../output
(cd ./../output;
jar cfm Game.jar MANIFEST.MF * ./../source/resources/*.png
chmod +x ./Game.jar
java -jar Game.jar ./../source/media/
)

Thanks! Seems to work now after just adding the resource files in the jar command. :)
 

BufferedImage image = null;
try {
	image = ImageIO.read(new File(this.externalMediaPath + fileName));
} catch(IOException e) {
	try {
		image = ImageIO.read(Class.class.getResourceAsStream("/source/resources/" + fileName));
	} catch(IOException f) {
		f.printStackTrace();
		System.out.println("Image not found at " + fileName + "!");
		return -1;
	}
}

When the selected mod folder does not contain the image, it will now fall back on the built in resources.
I should probably check if the files exist before trying to load from one location at a time but I can fix that later.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!