Asimov Technologies
J2EE, JEE, PHP
Frank D. Martínez’s Blog
Software & Fun
Welcome to my technical blog. Here you can find my opinions and proposals over many software development things, mainly on open source projects.
Glassfish + Quartz + EJB
How to configure Quartz in Glassfish V2. With this configuration you can schedule jobs from EJBs, Servlets, MDBs …
Approach:
- Make a Web application that acts as a Quartz Server (RMI)
- Configure Glassfish to allow RMI communication with the Webapp
- Make a test EJB
Make a Web application that acts as a Quartz Server (RMI):
Create normal webapp with the following libs packed in WEB-INF/lib:
- quartz-1.6.5.jar
- commons-collections-3.2.jar
- commons-logging-1.1.jar
include quartz.properties file in WEB-INF/classes with the following entries:
org.quartz.scheduler.instanceName = Sched1
org.quartz.scheduler.rmi.export = true
org.quartz.scheduler.rmi.registryHost = localhost
org.quartz.scheduler.rmi.registryPort = 1099
org.quartz.scheduler.rmi.createRegistry = true
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
Add this to the web.xml:
<listener> <listener-class>org.quartz.ee.servlet.QuartzInitializerListener</listener-class> </listener>
add to sun-web.xml:
<class-loader delegate="true"/>
Configure Glassfish to allow RMI communication with the Webapp:
Activate the Security Manager:
Go to Glassfish Admin Console, Go to [Configuration -> Security] and activate [Security Manager]
Edit server.policy file placed in the domain config folder, and add the following rule:
grant codeBase "file:${com.sun.aas.instanceRoot}/applications/j2ee-modules/[web app name]/WEB-INF/lib/quartz-1.6.5.jar” {
permission java.security.AllPermission;
};
replace [web app name] with the apropiate name.
Ok. that is all. Copy the war to the autodeploy dir and restart Glassfish.
Make a test EJB:
Package the following jars into the ejb jar:
- quartz-1.6.5.jar
- commons-collections-3.2.jar
- commons-logging-1.1.jar
put quartz.properties file in jar root with the following entries:
org.quartz.scheduler.instanceName = Sched1 org.quartz.scheduler.logger = schedLogger org.quartz.scheduler.rmi.proxy = true org.quartz.scheduler.rmi.registryHost = localhost org.quartz.scheduler.rmi.registryPort = 1099
Ok. It is ready, now you can access the Scheduler from any EJB:
SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler();
Download sample code:
Node: All dependency jars were removed, just download quartz-1.6.5.jar, commons-collections-3.2.jar, commons-logging-1.1.jar from Quartz home site and put it in lib dir in both projects.
original post in spanish: http://www.frankdavidmartinez.com/2009/03/glassfish-quartz-ejb/
This site contains personal opinions about many things and does not intend to be normative in any aspect.
Java, J2EE, J2SE, JEE, Are trademarks of Sun Microsystems Inc.