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 in MyApp.app/contents/resources/java
. The AutoUpdater.jar
should look something like this:
main()
{
if [ -x Applications/MyApp.app];then
cd Applications/MyApp.app/contents/resources/java
java AutoUpdater.jar
wait 86400
main
else
wait 3600
fi
}
main
The next bit of code will attempt to see if the app exists every hour and update daily if left running.
download()
{
cd Applications/MyApp.app/contents/resources/java
if ! curl -LO http://your.url.that.it.is.updating.from;then
echo "Failed to download"
wait 3600
else
wait 86400
fi
}
You can completely remove AutoUpdate.jar
by adding this to the code before the last line. Replace this:
java AutoUpdater.jar
wait 86400
... with this:
download
This is designed only for JarBundler
apps. You should use this to replace the current .jar file.
if ! curl -LO http://cbukk.it/craftbukkit-dev.jar;
As a side note, the command user.dir
usually gets /Users/yourName
as the path. You could change this to use a global identifier in JarBundler
like so:
String path = com.mycommpany.myapp;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.