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/
EAC4J: Apache Commons Configuration via JNDI, and without dependencies!
With EAC4J (External Application Configuration For Java) you can externalize your application’s configuration with Apache Commons Configuration and get a Configuration Object via simple JNDI lookup. The isolated classloader decouples all needed classess and dependencies from your application except by one interface.
This is a simple Wrapper over Apache Commons Configuration, so you get all the power of it but decoupled from any additional dependency jar. And additionally you can easy reload the configuration without restart the server.
This was initially developed for Glassfish V2 and has been tested on it only.
Glassfish V2 integration:

1. Download the zip here.
2. Unzip it in some folder
3. There will be some files and a directory:
- eac4j-api.jar Contains shared interfaces and utilities
- eac4j-impl.jar Contains the Apache Commons Configuration Wrapper
- eac4j-demo.war Contains a web application demo.
- config.xml Contains a sample configuration file.
- app.properties Contains a sample configuration file.
- deps Contains all dependency jars
- all.src.zip Contains all source code.
4. Copy eac4j-api.jar into ${glassfish-domain-root}/lib/ext
5. Create folder ${glassfish-domain-root}/lib/eac4j
6. Copy eac4j-impl.jar into ${glassfish-domain-root}/lib/eac4j
7. Copy all files from deps to ${glassfish-domain-root}/lib/eac4j
8. Restart Glassfish
9. Copy config.xml and app.properties somewhere together (And remember where)
10. Open the Admin Console
11. Go to Resources - JNDI - Custom Resources - New
12. Fill the fields: (see the screenshot) IMPORTANT: Do not forget Property configFile

13. deploy eac4j-demo.war
14. Try http://localhost:8080/eac4j-demo/DemoServlet on your browser.
Replace ${glassfish-domain-root} for your glassfish domain root: for example /var/glassfish/domains/domain1
That’s all, see the source code of eac4j-demo (Just one class: DemoServlet.java) to see how to use it in your applications, the class JNDIServiceLocator.java is just a service locator.
See the Apache Commons Configuration documentation for further details.
If you have any problem, please tell me. If you want to test it in another Application Server, please share your experience.
Thanks,
Frank.
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.