Jcrontab

*download Jcrontab
Next Release Plan
Javadoc
FAQ
wanna help?
some useful resources
Who is Who?

FAQ

Q: How can I use Jcrontab with tomcat?
Q: How can I change the crontab to any other file/path?
Q: How can I launch a native program with Jcrontab?
Q: How can I embed in Jcrontab in my application?
Q: How can I use SQL/DD.BB. with Jcrontab?
Q: Where can i find the next releases plan?

Q: How can I use Jcrontab with tomcat?

A: Jcrontab is useful with any app-server that supports servlets. You have to use org.jcrontab.web.loadCrontabServlet and set this servlet as a load-on-startup servlet.

Usually this is done with:

	<!-- This is the loadOnStartupServlet in order to launch jcrontab with the 
		application server -->
	<servlet>
		<servlet-name>LoadOnStartupServlet</servlet-name>
		<servlet-class>org.jcrontab.web.loadCrontabServlet</servlet-class>
	<!-- can overwrite the parameters from jcrontab.properties -->
	<!-- simply adding here the right parameters -->
        <init-param>
            <param-name>org.jcrontab.data.file</param-name>
            <param-value>YOURHOME/.jcrontab/thisfileoverwritesjcrontab.properties</param-value>
        </init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<!-- Mapping of the StartUp Servlet -->
	<servlet-mapping>
		<servlet-name>LoadOnStartupServlet</servlet-name>
		<url-pattern>/Startup</url-pattern>
	</servlet-mapping>

If you have your load-on-startup in your system and don't want to use the Jcrontab one, you can copy directly from loadCrontabServlet.java. In this file you'll see how Jcrontab can be initialized.

This has been tested in:

  • resin-caucho
  • jakarta-tomcat
  • jetty(4.0D1)
  • Jboss

Send your tests!

Q: How can I change the crontab to any other file/path?

A: This can be done easily by editing the org/Jcrontab/data/jcrontab.properties file.

Q: How can I launch a native program with Jcrontab?

A: Assuming we are talking about anything you can launch from your console and we are not talking about programs with user interaction (i.e., most "windows" programs, write your password). It's quite easy. You have two options: write your own wrapper, or launch this one. If you want to see an example you can take a look at src/org/jcrontab/ nativeExec.java. This example explains how to get input from the program, error and how to pass parameters.

If you don't want to write your own wrapper, you can use org.jcrontab.nativeExec as the task and pass the name of the program you want to launch as parameters. For example,

* * * * * org.jcrontab.nativeExec ls -la

will launch native ls -la every minute of every hour.

And that's it. You can launch more or less everything with Jcrontab.

Q: How can I embed in Jcrontab in my application?

A: This can be easily done; use org.jcrontab.jcrontab to find inspiration. But basically you have to get the system Crontab, init, and then just wait for Crontab to do the job.

----------------------------------------------------------------------
private Crontab crontab = Crontab.getInstance();
crontab.init("yourPropertiesFile", 60);
-----------------------------------------------------------------------

crontab.init() does its job and starts the cron thread.

Q: How can I use SQL/DD.BB. with Jcrontab?

A: You can take a look at jcrontab/etc/create.sql; it has the definition of tables to work with jcrontab, but if you want to use other tables, you can change src/org/jcrontab/data/GenericSQLSource.java, and adapt the queries to your tables.

When you're done with the model and the GenericSQLSource.java, adapt jcrontab.properties to your needs and that should do it.

org.jcrontab.data.datasource = org.jcrontab.data.GenericSQLSource
org.jcrontab.data.GenericSQLSource.driver = org.gjt.mm.mysql.Driver
org.jcrontab.data.GenericSQLSource.url = jdbc:mysql://yourmachine.jcrontab.org:3306/jcrontab
org.jcrontab.data.GenericSQLSource.username = iolalla
org.jcrontab.data.GenericSQLSource.password = yourpassword

If this GenericSQLSource.java isn't self-explanatory, the idea is that "org.jcrontab.data.DataSource" should give the info necessary to build a org.jcrontab.CrontabEntryBean.

Q: Where can i find the next releases plan?

A: If you are looking for a specific feature feel free to send an email to iolalla@yahoo.com with your suggestions. But can find a planned relese at this site.