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
paddyfitz2005Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

radarshCommented:
>> i don't know how to compile the script to run the java file

What script do you want to run? How is it scheduled to run? In the script or
in the Java Application itself?

________
radarsh
paddyfitz2005Author Commented:
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.com"
15  23  *  *  *       /usr/ngasi/contexts/myaccount/myscript.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
x4uCommented:
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)
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

x4uCommented:
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.
CEHJCommented:
>>i don't know how to compile the script to run the java file

You don't compile scripts - scripts are text files. If you're on Windows, you need a batch file

@echo off
java -classpath <whatever> YourApp

will do it. Save the above (with appropriate alterations) in the batch file directory
Mick BarryJava DeveloperCommented:
> I just want to know how i can launch a java file  in a .sh script file

Same way you would run it from the command line

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paddyfitz2005Author Commented:
>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.NoClassDefFoundError: 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
x4uCommented:
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.

Mick BarryJava DeveloperCommented:
and make sue you make it executable
paddyfitz2005Author Commented:
>>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>


Mick BarryJava DeveloperCommented:
javac g:\Java\Tomcat 5.5\webapps\DBTest\Updater.java
paddyfitz2005Author Commented:
>>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
Mick BarryJava DeveloperCommented:
g:
cd \Java\Tomcat 5.5\webapps\DBTest
javac Updater.java
x4uCommented:
I didn't notice that you have a space in your path. You will need to put such pathnames in double quotes then. i.e.:

javac "g:\Java\Tomcat 5.5\webapps\DBTest\Updater.java"
java -cp "G:\Java\Tomcat 5.5\webapps\DBTest" Updater


CEHJCommented:
>>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)
paddyfitz2005Author Commented:
sorry didn't see that, how can i resplit the points?
CEHJCommented:
You can just reopen it - i'll do it for you, so you need do nothing at the moment
paddyfitz2005Author Commented:
how do i reopen it?
CEHJCommented:
Don't worry - you'll get a notification telling you it's reopened
x4uCommented:
>> 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
>>
CEHJCommented:
>>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
paddyfitz2005Author Commented:
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
CEHJCommented:
Never mind paddyfitz2005. I missed that earlier comment about the command, although no-one seems to have said much about scripts ;-)
CEHJCommented:
You beat me to it - thanks anyway
x4uCommented:
Don't worry paddyfitz2005, it's just a game. ;-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.