views:

295

answers:

3

I have created a jar file in java, and I want to make the application automatically start during system boot up. I found I have to write a shell script for that. What should be that shell script look like? Is there anything else I have to do to make an application automatically start at boot up?

A: 

The shellscript would be something like this:

cd /directory/to/jar
java -jar Jar.jar

Or maybe you don't actually need to write Jar.jar, only Jar. I don't quite remember.

ygd
+1  A: 

In mac os x you can also just run "open program.jar" (or any folder, '-a' for native applications) and it will open detached from the terminal with any default environment settings that it would use if you just double clicked it.

You can also add a program (or the script) to the user's login items through System Preferences > Accounts > 'username' > Login items. This is completely point and click and doesn't require a shell script

Mobs
Login items are launched when a user logs in, not during system boot as the OP requested.
Ned Deily
True, but most macs are set to auto login ime - thus achieving the same goal.. but thats up to the thread starter to decide if it works for his situation.
Mobs
Heh, I think I've run OS X without auto login since Preview day 1 so I wouldn't have even considered that as an option. I certainly don't recommend depending on auto login.
Ned Deily
+2  A: 

The preferred way to launch programs at OS X startup is to create a launchd daemon as explained here.

Ned Deily
Hi Ned Deily, I read the article. But i found a problem. There I found how to run the time based cron file. But what we have to write to run the application during startup is not mentioned. let ex1.app is my applicatio file. Then what I have to write to start that aplocation during startup
Deepak
The relevant information is the section `Creating A Startup Script`. You should also find man pages on your system for launchd, launchd.plist, and launchctl. And even though it is no longer being maintained, Peter Borg's free Lingon application (http://lingon.sourceforge.net/) makes it easy to create and modify launchd.plists.
Ned Deily
Thanks Ned Deily, Really your reponse helped me alot. Thanks for your support. Take Care.
Deepak