10

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..

1
  • 1
    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... Commented May 5, 2012 at 6:17

3 Answers 3

9

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.
Sign up to request clarification or add additional context in comments.

4 Comments

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??
You need to set classpath/path variables in your system.
@blue add this in your answer too ulrichpalha.com/myblog/2011/11/19/…
It's been a long time since this question has been asked, but in case anyone is reading this later on, writing your batch and then creating a Windows link (right click>Create Link) and copying the link in the startup folder avoids the classpath problems
1

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/

Thanks.

1 Comment

doesn't while(true) load a processor 100%?
-3

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

1 Comment

crontab is for scheduling, not for auto-start

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.