paddyfitz2005
asked on
Java Cron Job
Bascially i want to be able to run a cron job that will execute my java file updater.java every night at midnight.
My web server allows me to run cron jobs but i don't know how to compile the script to run the java file
I'm using windows and most tutorials on the subject are using linux
Please Help
My web server allows me to run cron jobs but i don't know how to compile the script to run the java file
I'm using windows and most tutorials on the subject are using linux
Please Help
ASKER
This is the information i got from my website provider:
-------------------
The Cron Job feature allows you to set Cron Jobs from the Web Console.
You cannot have more than 1 script starting at the same time.
The duration of the script may not be more than 1 hour.
Remember to make the script file as executable. Please refer to a Linux/Unix book
if not sure how to.
NOTE: You may also use the system command "crontab" to set Cron jobs.
If using the System cron you may specify the output to be mailed to
a specific email address with the MAILTO environment. The following
is a brief example of how to create a cron (for more details please refer
to a Linux/Unix book).
Login to your account via SSH/Telnet.
Create a file called mycron and add the following:
MAILTO="name@yourdomain.co m"
15 23 * * * /usr/ngasi/contexts/myacco unt/myscri pt.sh
Save the file and enter the following command:
crontab mycron
The above cron job will run everyday at 11:15PM and execute
"myscript.sh". Any output will be emailed to "name@yourdomain.com".
-------------------------- ---------- ---------- ----------
I just want to know how i can launch a java file in a .sh script file
-------------------
The Cron Job feature allows you to set Cron Jobs from the Web Console.
You cannot have more than 1 script starting at the same time.
The duration of the script may not be more than 1 hour.
Remember to make the script file as executable. Please refer to a Linux/Unix book
if not sure how to.
NOTE: You may also use the system command "crontab" to set Cron jobs.
If using the System cron you may specify the output to be mailed to
a specific email address with the MAILTO environment. The following
is a brief example of how to create a cron (for more details please refer
to a Linux/Unix book).
Login to your account via SSH/Telnet.
Create a file called mycron and add the following:
MAILTO="name@yourdomain.co
15 23 * * * /usr/ngasi/contexts/myacco
Save the file and enter the following command:
crontab mycron
The above cron job will run everyday at 11:15PM and execute
"myscript.sh". Any output will be emailed to "name@yourdomain.com".
--------------------------
I just want to know how i can launch a java file in a .sh script file
Download the Java SDK from sun and install it. ( http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_06-oth-JPR&SiteId=JSC&TransactionId=noreg )
Run the compiler with: C:\jdk1.5.0_06\bin\javac updater.java
(depends on where you installed the jdk)
Use a cron job like this: java -cp your_dir updater
(your_dir is the the directory where you compiled your Java file)
Run the compiler with: C:\jdk1.5.0_06\bin\javac updater.java
(depends on where you installed the jdk)
Use a cron job like this: java -cp your_dir updater
(your_dir is the the directory where you compiled your Java file)
The webserver is not running on your own maschine? Then you will have to compile it on your own maschine and upload the compiled .class files to the webserver. If only Java 1.4 is installed on the webserver you will need to use "C:\jdk1.5.0_06\bin\javac -target 1.4 updater.java" to compile the Java code.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
>Use a cron job like this: java -cp your_dir updater
I tried to run it from my command prompt with the following: G:\> java -cp . Java\Tomcat 5.5\webapps\DBTest\Updater
but i get the following error :: Error: Exception in thread "main" java.lang.NoClassDefFoundE rror: Java\Tomcat
but if i run it like this it works: G:\Java\Tomcat 5.5\webapps\DBTest>java -cp . Updater
-----------
So basically all a i need to do is put the corect command into a file called script.sh and I will be able to run it as a java file?
Thanks for your comments
I tried to run it from my command prompt with the following: G:\> java -cp . Java\Tomcat 5.5\webapps\DBTest\Updater
but i get the following error :: Error: Exception in thread "main" java.lang.NoClassDefFoundE
but if i run it like this it works: G:\Java\Tomcat 5.5\webapps\DBTest>java -cp . Updater
-----------
So basically all a i need to do is put the corect command into a file called script.sh and I will be able to run it as a java file?
Thanks for your comments
Yes and you can also use it this way: java -cp G:\Java\Tomcat 5.5\webapps\DBTest Updater
This allows you to call it from every directory you like.
This allows you to call it from every directory you like.
and make sue you make it executable
ASKER
>>you can also use it this way: java -cp G:\Java\Tomcat 5.5\webapps\DBTest Updater
Im still getting the same error when i do it this way?
Also when i try to compile it i get this error
G:\>javac Java\Tomcat 5.5\webapps\DBTest Updater.java
javac: invalid flag: Java\Tomcat
Usage: javac <options> <source files>
Im still getting the same error when i do it this way?
Also when i try to compile it i get this error
G:\>javac Java\Tomcat 5.5\webapps\DBTest Updater.java
javac: invalid flag: Java\Tomcat
Usage: javac <options> <source files>
javac g:\Java\Tomcat 5.5\webapps\DBTest\Updater .java
ASKER
>>javac g:\Java\Tomcat 5.5\webapps\DBTest\Updater .java
This is strange i don't know what i'm doing wrong!
G:\>javac g:\Java\Tomcat 5.5\webapps\DBTest\Updater .java
javac: invalid flag: g:\Java\Tomcat
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are u
sed
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
This is strange i don't know what i'm doing wrong!
G:\>javac g:\Java\Tomcat 5.5\webapps\DBTest\Updater
javac: invalid flag: g:\Java\Tomcat
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are u
sed
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
g:
cd \Java\Tomcat 5.5\webapps\DBTest
javac Updater.java
cd \Java\Tomcat 5.5\webapps\DBTest
javac Updater.java
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
>>java -cp "G:\Java\Tomcat 5.5\webapps\DBTest" Updater
Mentioned that earlier:
>>
@echo off
java -classpath <whatever> YourApp
>>
(cp is the same as classpath)
Mentioned that earlier:
>>
@echo off
java -classpath <whatever> YourApp
>>
(cp is the same as classpath)
ASKER
sorry didn't see that, how can i resplit the points?
You can just reopen it - i'll do it for you, so you need do nothing at the moment
ASKER
how do i reopen it?
Don't worry - you'll get a notification telling you it's reopened
>> Mentioned that earlier:
...
Didn't I write it even earlier? ;-) I just repeated it to show where to place the double quotes.
>>
Use a cron job like this: java -cp your_dir updater
>>
...
Didn't I write it even earlier? ;-) I just repeated it to show where to place the double quotes.
>>
Use a cron job like this: java -cp your_dir updater
>>
>>Didn't I write it even earlier?
You did mention it earlier, but it would seem that i was the only one to mention scripts and how to use them
You did mention it earlier, but it would seem that i was the only one to mention scripts and how to use them
ASKER
This is the thing i hate about ee, theres always a dispute about who answered what and when. I'm going to split the points between the 3 guys and if you don't like it tough luck
Never mind paddyfitz2005. I missed that earlier comment about the command, although no-one seems to have said much about scripts ;-)
You beat me to it - thanks anyway
Don't worry paddyfitz2005, it's just a game. ;-)
What script do you want to run? How is it scheduled to run? In the script or
in the Java Application itself?
________
radarsh