I have made an Mac application MyApp.app with Jar Bundler. Because I have an external jar, lib/AutoUpdate.jar that is in the same folder path as the MyApp.app, I need the current path of the MyApp.app to be able to run auto-updates.
Apparently:
System.getProperty("user.dir");
Dose not work. I also tried:
String path = System.getProperty("user.dir");
if(path.contains("/MyApp.app")){
int i = path.indexOf("/MyApp.app");
path = path.substring(0,i);
}
But this also seems to be incorrect path of the MyApp.app. Any ideas how to get the correct path or if I at least can debug the the MyApp.app to get a view of System.out.println() commands?
Try
Applications/MyApp.appfor the location if it is in the given area, or you could use a Unix command to launch the jar at the desired directory (and not hardcode it into the.jarfile).-xis used for executables, but apps usually also work with-dand all work with-ecommands.To implement, place your
AutoUpdater.jarwith the other .jar files inMyApp.app/contents/resources/java. TheAutoUpdater.jarshould look something like this:The next bit of code will attempt to see if the app exists every hour and update daily if left running.
You can completely remove
AutoUpdate.jarby adding this to the code before the last line. Replace this:... with this:
This is designed only for
JarBundlerapps. You should use this to replace the current .jar file.As a side note, the command
user.dirusually gets/Users/yourNameas the path. You could change this to use a global identifier inJarBundlerlike so: