Referencing bundled folders (not assets.jar) in a macOs distributable

I include a large number of files along with my jar, I load them out of the bundled folder rather than using a class loader because folder operations need to be made on them (i.e. its inconvenient but obviously not technically impossible to have to know what files exist ahead of time, the files are effectively specialized save game files and being able to load them in the same way as the save games is really useful).

I can make this work in windows and presumably linux (untested) by modifying the desktop-deployment-imp.xml to bundle the assets folder as a sibling of the .jar. This means a relative path of assets/…/ resolves to my load resources.

However within MacOs relative paths seem to be relative to the users home directory rather than relative to the jar or app. Is there any way to make it relative to the jar? (or relative to any part of the generated .app directory which contains everything).

So in that image all relative paths are relative to users/Admin

To further justify this way of working:

  • These SeedChunkSets literally are a partial version of the save game files, in game machines can be built and saved and these are just default ones that come with the game, so they are saved in the same way. Introducing two ways to load the same thing would be a bit nasty
  • A machine is represented by a folder, not by a file, this folder contains parts of the machine in a chunked format so what files are contained within this folder always varies, one might just contain 0,0.ser, another may contain 0,0.ser 16,0.ser and 16,16.ser. As I understand it you can treat things from the assets.jar as files, but not as folders, so “what does this folder contain” is not a question you can ask it

Well, you can’t reset “user.home” and I can find “java.home”. I think you can access the current directory. I access a database but, I’m working on a PC and I have it in my application dir.

You should dive into java properties. You want the current directory, I think. I see “user.home” and “java.home”. I’ve printed out a lot of properties but I can only find my code for these.

And know, the \ (back slash) is the meta character. It allows you to use quote marks in a string. They look like they are coming out ok here.

Here:
https://docs.oracle.com/javase/8/docs/api/java/lang/System.html
“user.dir”

private boolean checkReadJavaHomeDirPermission(){
	boolean b = true;

	//check modifyThreadGroup for Java3D
	try {
		PropertyPermission pp = new PropertyPermission("java.home", "read");
		AccessController.checkPermission(pp);
		System.out.println("java.util.PropertyPermission \"java.home\" \"read\" permission OK");
		System.out.println("\"java.home\" is " + System.getProperty("java.home", "read"));
	}
	catch (AccessControlException e){
		System.out.println("Cannot read property \"java.home\" in java.policy file");
		System.out.println();
		b = false;
	}
	return b;
}


private boolean checkReadUserHomeDirPermission(){
	boolean b = true;

	//check modifyThreadGroup for Java3D
	try {
		PropertyPermission pp = new PropertyPermission("user.home", "read");
		AccessController.checkPermission(pp);
		System.out.println("java.util.PropertyPermission \"user.home\" \"read\" permission OK");
		System.out.println("\"user.home\" is " + System.getProperty("user.home", "read"));
		
	}
	catch (AccessControlException e){
		System.out.println("Cannot read property \"user.home\" in java.policy file");
		System.out.println();
		b = false;
	}
	return b;
}

private void checkJoglDebug(){
	boolean b = false;
	String prop = "jogamp.debug.JNILibLoader.Perf";
	String result = "";

  //PERF = DEBUG || PropertyAccess.isPropertyDefined("jogamp.debug.JNILibLoader.Perf", true);
	//try {
		//AccessController.checkPermission(pp);
		//System.out.println("\"user.home\" is " + System.getProperty("user.home", "read"));
		//PropertyPermission pp1 = new PropertyPermission("home.user", "read");//jdk 1.8.0_60
		//AccessController.checkPermission(pp1);
		//System.out.println("\"" + "home.user" + "\" \"read\" permission OK");

		//PropertyPermission pp = new PropertyPermission(prop, "read");//jdk 1.8.0_60
		//AccessController.checkPermission(pp);
		System.out.println("\"" + prop + "\" \"read\" permission OK");
		b = PropertyAccess.isPropertyDefined(prop, true);
		result = PropertyAccess.getProperty(prop, true);
		System.out.println("\"" + prop + "\" \"" + result + "\" " + b);
	//}
	//catch (AccessControlException e){
	//	System.out.println("Cannot read property \"" + prop + "\" in java.policy file");
	//	System.out.println("\"" + prop + "\" \"" + result + "\" " + b);
		//System.out.println();
		//b = false;
	//}
	//return b;
}

I have implemented the method:

to find a folder where a class’es jar is, it works on all desktop OS :wink:

2 Likes

Well that looks like exactly what I need. I’ll gIve it a try tonight. Thanks!

1 Like

you can use my library in your project easy, just include it as a dependency :wink: