Sign in to follow this  
Dawoodoz

Building jar with resources without IDE

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this