Running a JAVA program as a scheduled task

老子叫甜甜 提交于 2019-11-27 08:54:46

I Think that you could create a simple batch script that will launch your program in this way :

@echo off
REM Eventually change directory to the program directory 
cd C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\
REM run the program
"C:\Program Files\Java\jdk1.7.0\bin\java.exe" -jar "C:\Users\User1\Documents\NetBeansProjects\Facebook\dist\Facebook.jar"

Copy it into the notepad and save as java_script.cmd and then schedule this script instead of the program directly.

I solved it after changing all fonts' references to "SansSerif"

I was using Jasper Reports inside Java to create a PDF file. It was working fine when I double click the batch file or Scheduler with Windows Server 2003 but not working with the Scheduler of 2008.

I tried many different things nothing worked so I though Could it be that Windows Server 2008 is blocking the access?.

Now is working perfect. So, if you are having problems check the references to anything you are using.

The scheduler will run under a different user unless you specify what user to run as. If it isn't running as your user then it won't be able to write to your directories.

The real problem to the original question is a java installation issue on Microsoft systems. Java jre installs into Program Files\java. The executable (java.exe) is only installed in that java\bin directory. Running from the command line, the os looks in the proper location for the java.exe. Running from other MS tools (such as VBA Excel or in this case TaskScheduler), it does not!

You can see that TaskScheduler is looking in the wrong place by viewing the tasks history in the TaskScheduler tool. Double click on some of the history events and one will list the action and return code. The action will show that the TaskScheduler is trying to run

"C:\Windows\system32\java.EXE"

So, copy java.exe from the java\bin directory into the place where the scheduler is looking, and now it will work.

Or update your task and provide the full path to java.exe.

You can also update the environment system path to look for java in the java\bin directory, but that has to apply to all users and sometimes this is faulty as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!