• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

linux cron task to invoke java class

 
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

we have implemented a complex java module for searching relational databases.our database server is hosted on a linux machine.
in this java module, there is the feature of indexing database data.
one requirement in our project is to refresh the index daily & weekly with some sort of automatic cron task .

we would like to know how we can write a Linux shell script to invoke our index refresher (java class) automatically .and how can we schedule the index refresher so it is invoked automatically every day at a given time. we would also prefer to make the scheduling configurable (change time ,date ).

what is the best approach to implement this task ?

thank you for sharing your ideas with us.
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Calling a Java class from a shell script is very straightforward. You can can do something like this.


To set a scheduled task in Linux/UNIX, you can use crontab. Add a new entry in the crontab to call that shell script. For more information, do man crontab. This should also be fairly straightforward.
 
Yahya Elyasse
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for prompt & very clear reply.

we will try this method.
thanks again.
 
Yahya Elyasse
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Actually i need to write a java command line utility that could be run in same way (like ant for example) in various OS.

for example if we call this cmd line utility 'abc' then it should be invoked from command line (unix) like : $abc [parameters options] (example: $ ant build.xml).
if i write a java command line application and want to invoke it as a cmd line utility with a given name 'abc' and list of params ,how can i do that ?

thanks.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hopefully I get you correctly.

Actually ant/java command itself isn't platform independent. If you're in Windows, it's called ant.exe or java.exe and if you're in Linux is just called ant or java. Both are binary files. You can't run ant.exe/java.exe in Linux and vice versa. All I want to say is both are different binaries even though they have the same name.

If you're thinking on writing a script, most of the projects that I know will provide the .bat or .cmd if it's used for Windows environment and .sh if it's used in Linux/UNIX environment. Take a look at tomcat. You'll see that there's catalina.bat in Windows and catalina.sh in Linux.

Hope it's clear enough for you.
 
Yahya Elyasse
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Freddy Wong:
Hopefully I get you correctly.

Actually ant/java command itself isn't platform independent. If you're in Windows, it's called ant.exe or java.exe and if you're in Linux is just called ant or java. Both are binary files. You can't run ant.exe/java.exe in Linux and vice versa. All I want to say is both are different binaries even though they have the same name.

If you're thinking on writing a script, most of the projects that I know will provide the .bat or .cmd if it's used for Windows environment and .sh if it's used in Linux/UNIX environment. Take a look at tomcat. You'll see that there's catalina.bat in Windows and catalina.sh in Linux.

Hope it's clear enough for you.



Thanks anyway , i'm aware of the fact that those are binaries targeted to different os. i was wondering if it's easy to convert a java cmd line app into a binary ?(exe on windows or bin on linux).
if i'm not wrong this will involve using jini right ?

If i use a bash script for launching the java program ;how can i pass cmd line parameters to bash script and make them available as command arguments for the java program ?

thanks.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


If i use a bash script for launching the java program ;how can i pass cmd line parameters to bash script and make them available as command arguments for the java program ?


This should be easy


So to invoke that script, let's name it MyScript.sh
$ ./MyScript.sh arg1 arg2 arg3

Hope this helps.
 
Yahya Elyasse
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks much

your help is much appreciated.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Freddy Wong:
Actually ant/java command itself isn't platform independent. If you're in Windows, it's called ant.exe or java.exe and if you're in Linux is just called ant or java. Both are binary files. You can't run ant.exe/java.exe in Linux and vice versa. All I want to say is both are different binaries even though they have the same name.

If you're thinking on writing a script, most of the projects that I know will provide the .bat or .cmd if it's used for Windows environment and .sh if it's used in Linux/UNIX environment.



If you call java in Windows, the system will look for a java.bat, if not present for java.com, and finally for a java.exe - afaik.
So if there is no java.bat and no java.com, you may call java java on windows too - but there is a funky drive letter and slashes the other way round - probably a complete different path.

And there is a sh-like-shell for windows too: http://gnuwin32.sourceforge.net/

But I guess the problem is already solved,
 
Do not threaten THIS beaver! Not even with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic