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.app
for 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.jar
file).-x
is used for executables, but apps usually also work with-d
and all work with-e
commands.To implement, place your
AutoUpdater.jar
with the other .jar files inMyApp.app/contents/resources/java
. TheAutoUpdater.jar
should 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.jar
by adding this to the code before the last line. Replace this:... with this:
This is designed only for
JarBundler
apps. You should use this to replace the current .jar file.As a side note, the command
user.dir
usually gets/Users/yourName
as the path. You could change this to use a global identifier inJarBundler
like so: