I am very new in developing world so my apologies in advance if my question sounds weird. I have written a test with Selenium and JAVA and made a jar file from it, now I am wondering if there is any way that this jar file can be run every 1 hour automatically, I mean there should be no one clicking on the jar file or any running program to run it.
-
On unix systems you can create a cronjob. Windows might have a similar feature. – user Aug 11 '15 at 16:28
-
@user could you please explain more? and what about windows? – Aug 11 '15 at 16:29
-
@LoveJava You have to use a job scheduler.Unix provides cronjob,Windows has Task Scheduler,BTW nice name LoveJava – Kumar Abhinav Aug 11 '15 at 16:30
-
@KumarAbhinav any way that I can put them in the jar file ? – Aug 11 '15 at 16:31
-
@LoveJava You cannot do that,its an underlying OS mechanism.What you should do is have the main Java program running continuously and a child process spawning every 60*60*1000 milliseconds – Kumar Abhinav Aug 11 '15 at 16:33
-
@KumarAbhinav thanks, could you send this as an answer please. – Aug 11 '15 at 16:35
-
@LoveJava Well you have the answer,but only if you say so :D – Kumar Abhinav Aug 11 '15 at 16:36
-
@KumarAbhinav I say so :D so please post it as the answer :) – Aug 11 '15 at 16:37
-
@LoveJava: if you want to include this "run on timer" functionality inside a JAR file, you should look at some kind of a job scheduler like Quartz: http://quartz-scheduler.org/. You will have then a single Java process running constantly, which executes your task every hour. – Maciej Lach Aug 11 '15 at 16:55
-
quartz might be a bit of an overkill (learning, configuration) for just running one job (Thread.sleep will work just as well as long as you are careful not to throw out of your main loop), but it works well for big projects. Heck add in Spring and Tomcat and you will have almost no code and you can just spend all your time learning, setting up and configuring. – Bill K Aug 11 '15 at 17:00
4 Answers
- Open Task Scheduler and Create Task (on right side).
- Add a Name on the General tab.
- On the Triggers tab, click New...
- In the popup, select daily
- then in the advanced you can select Repeat Task every: 1 hour
- On the Actions tab, click New...
- Browse and select your program
- Click OK to create the task.

- 1,002
- 13
- 24
-
-
-
Since it's a java program you might not be able to just put the name of your jar in there--instead put java -jar yourJar.jar – Bill K Aug 11 '15 at 16:45
-
-
You would have to install Linux software on Windows to get the same thing to work on both. You could probably use Cygwin and install Chron pretty easily. The scheduling mechanism is part of the OS. If you started a long-term java job that just triggered itself it would work but would require you to leave a terminal open the entire time which is not overly professional. You could also use a container like "Tomcat", then there are lots of ways to do that and you can get the tomcat to run as a service on both windows and Linux easily-however, configuring Tomcat is yet another thing to learn. – Bill K Aug 11 '15 at 16:55
You can use an OS built job scheduler or use a tool which would make your jobs run.Also you could have a main Java program running infinitely and a child process spawning every 60*60*1000 milliseconds .

- 6,565
- 2
- 24
- 35
You can also run Jenkins, and create a job to execute the jar every hour. The nice part about this is you get a web-based UI and an easy way to view the output from the tests.

- 9,372
- 4
- 28
- 31
-
Although a strange concept, this has the added benefit that it would work on both windows and linux – Bill K Aug 11 '15 at 17:01
If you are on a unix based system, you could run the jar as a cronjob. The following would run a jar every 30 seconds.
0 */1 * * * java -jar /path/to/jar/myjar.jar Read the following to learn how to setup a cronjob correctly https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job
For windows, use task scheduler. Go to https://stackoverflow.com/a/26932169/802061 for more details.

- 1
- 1

- 806
- 8
- 21