0

I have a Java application that needs to implement installation features of making a JAR launch on startup.

I can do this on Window by entering a REG file into the registry, but how can I do this on UNIX platforms? Linux and Mac if the methods are different.

Do Linux and Mac have system startup folders?

Remember that I need to do this programmatically not through system preferences or anything like that.

bgroenks
  • 1,859
  • 5
  • 34
  • 63
  • What do you intend your program to do upon startup? – Gabe Feb 21 '12 at 04:32
  • @Gabe registers a SystemTray icon and checks to see when the next task is to be run. It will then sleep for a period of time and check again later for updates. I'm trying really hard to design it to be low-cost resource wise. That's hard with Java. I love Java, but long-running background tasks aren't where it shines. I wanted to make a C app to do this part... but that would only work on Windows and I can't figure out how to make a tray icon. – bgroenks Feb 21 '12 at 20:01

3 Answers3

1

On Linux, the classic way would be through adding a script in the appropriate /etc/rcN.d/ directory (where N is a number 0-6 representing the 'run level'). I'm not sure whether that's still the recommended way, but it usually is still supported. This would also work with minor variations for other mainstream Unix variants (Solaris, HP-UX, AIX).

On Mac, you have to work harder. The files /etc/rc.common, /etc/rc.imaging and /etc/rc.netboot are related, but there are no /etc/rcN.d directories. There's also a script rc and another rc.local. Typing man rc reveals:

DESCRIPTION

rc.local is now unsupported and has been replaced with launchd(8), which bootstraps itself via the launchctl(1) bootstrap subcommand to read in launchd(8) jobs from the standard locations.

SEE ALSO

launchd(8), launchctl(1)

So, you should investigate launchctl and launchd, particularly launchctl.

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Are those (launchctl, launchd, rc.common, ...) files or directories? – bgroenks Feb 21 '12 at 20:00
  • `launchctl` and `launchd` are programs (see `man launchctl` and `man launchd`) - the Launch Daemon and its control program. `rc.common` etc are files or scripts in `/etc/` on my Mac, which has been upgraded from earlier versions of Mac OS X so it might be a carry-over, but it is probably a file that's there on a clean new Lion install. – Jonathan Leffler Feb 21 '12 at 20:13
0

On Macs I think its launchd, and on linux its init.d. They are config files.

mellamokb
  • 56,094
  • 12
  • 110
  • 136
tik27
  • 2,698
  • 1
  • 16
  • 25
0

This is how I would do it on ubuntu.

First create a bash script to run the java app, similar to.

#!/bin/bash
java -jar "helloworld.jar"

and save it, in this case called 'HELLOWORLD' in /etc/init.d.

Need to make the script executable so need to run

chmod +x HELLOWORLD

Finally to make it run on start up

update-rc.d HELLOWORLD defaults
Dan675
  • 1,697
  • 15
  • 15