Help - Search - Members - Calendar
Full Version: How To Run A .jar File On Startup?
Linuxhelp > Support > Technical Support
Onestep
I've installed MrPostman, which is a .jar file, to fetch Hotmail into Thunderbird.
It works well, kinda buggy, but a keeper. I currently have to start MrP in the consol by:

java -jar MrPostman-20040616.jar

Is it possible to set this up to automaticaly start/run during boot-up?
I'd also like it to run "in the background" if possible. Right now
the consol is open when it runs.
hughesjr
Open your editor (as root) ... paste this into it:

CODE
#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

JAVA=/usr/bin/java

MRPOSTMAN=/full/path/to/MrPostman-20040616.jar

USER=username

/bin/su - $USER -c "$JAVA -jar $MRPOSTMAN &"


Substitute the full path to your java command (if you're not sure, do the command which java) for /usr/bin/java in JAVA= .... the full path to MrPostman-20040616.jar for /full/path/to/MrPostman-20040616.jar
in MRPOSTMAN= ... and the username that you normally run this command under for username in USER=.

Save the file as /usr/local/bin/mrpostman.sh

make it executable with the command:

chmod 755 /usr/local/bin/mrpostman.sh

As root ... run this command:

/usr/local/bin/mrpostman.sh

Then you should be able to do:

ps -ef | grep java

and your process (running as the correct user) should be present....if it works then...

You didn't mention your distro ... but most have a file named rc.local ... it is usually either in /etc, or /etc/rc.d, or /etc/init.d .... edit that file and add (at the very bottom of it):

/usr/local/bin/mrpostman.sh

reboot

it should work (if it worked from the command-line before).

-----------------EDITED 7/9/04 ------------------
I had initially included single quotes ( ' ) in the script on the last line ... it should have been double quotes ( " ). ---corrected
-------------------------------------------------
Onestep
I'll give it a whirl !
If it changes anything, I'm running Mandrake 10.0 Official

Thanks!!
Onestep
QUOTE
You didn't mention your distro ... but most have a file named rc.local ... it is usually either in /etc, or /etc/rc.d, or /etc/init.d .... edit that file and add (at the very bottom of it)


I'm using Mandrake 10.0 Official, and
I found (2) "rc.local" files. Does it matter which one I use?:

[root@bb-66-63-69-44 kurt]# /usr/bin/find / -name rc.local
/etc/rc.d/rc.local
/etc/rc.local
hughesjr
One is probably a link to the other one....in which case, it won't matter.

Do this:

ls -al /etc/rc.d/rc.local
ls -al /etc/rc.local

The normal one is in /etc/rc.d/rc.local
Onestep
QUOTE (hughesjr @ Jul 7 2004, 07:57 PM)
As root ... run this command:

/usr/local/bin/mrpostman.sh


When I do this, I get the following:

-bash: line 1: -jar: command not found


This is my executable file /usr/local/bin/mrpostman.sh :


CODE
#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

JAVA=/usr/bin/java

MRPOSTMAN=/usr/bin/MrPostman-20040616.jar

USER=kurt

/bin/su - $USER -c '$JAVA -jar $MRPOSTMAN &'

Any ideas where to go from here?
I've double checked the steps I took, looking for keying errors and such, but
it all looks o.k.
hughesjr
Try it with " instead of ' ... like this:

/bin/su - $USER -c "$JAVA -jar $MRPOSTMAN &"
Onestep
It WORKS !!

thanks again... so much to learn.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.