Take the 2-minute tour ×

I have a simple java program which is just a single piece of code that reads from a database and modifies the contents of the database based on certain conditions. Now, what I want is that this program should start automatically at the startup and silently run in the background unless someone kills it from the task manager. I have never done something like this before and don't know exactly how to go about it. Can someone help me out as to how this can be done? Thank you..

share|improve this question
Windows? Linux? –  Jim Garrison May 5 '12 at 6:16
You want your java application to run on startup? Why not put a bat file on the startup folder to start the java applicaiotn? That should get it done assuming it's windows... –  Thihara May 5 '12 at 6:17

3 Answers 3

up vote 1 down vote accepted

Follow the these steps to do the job :(Assuming you are using windows and jre is installed )

  • First compile your java program and place the class file at one location.
  • Now create a bat file and place java LOCATION TO THAT CLASS FILE/MyProgram in that.
  • Put your bat file in start up programs
  • Restart the system, you will get your program running in back ground..! Hope this will help you.
share|improve this answer
Thnx for the suggestion. But I am running into a bit of problem when I am giving the absolute path to the class file in the command. Its throwing this error "Exception in thread "main" java.lang.NoClassDefFoundError: C:\Documents and Settings\Desktop\Test". However if I migrate to the directory and then run the command, it works fine! Any insight into this?? –  sachin11 May 7 '12 at 7:03
You need to set classpath/path variables in your system. –  Ved May 7 '12 at 7:09
thanx a lot for the help:) –  sachin11 May 7 '12 at 7:46
my pleasure. :) –  Ved Dec 14 '12 at 13:07
@blue add this in your answer too ulrichpalha.com/myblog/2011/11/19/… –  user1542476 Dec 14 '12 at 13:08

There are two problems here

  1. How to add this program to the startup

  2. Run the program as a daemon (background process)

    • Simplest way to do is using a while loop and sleep for required time interval in the while loop. Then perform the database operation.

Also for windows, you can check this JSL http://www.roeschter.com/


share|improve this answer
doesn't while(true) load a processor 100%? –  Alexander Supertramp Nov 13 '13 at 12:11

first create you jar bash and then add it to you crontab task list. thanks

share|improve this answer

Your Answer


