help in struts application
Hi guys,
I'm using struts application,from that i will call
one external java file.(i.e) At the time of server(tomcat) will start ,the java class file is also started.
can u give any idea regarding my condition.I wrote some triggering logic in that Java file.
so, i need once the application will start, the corresponding java file will also called.
[382 byte] By [
SARAV_RSa] at [2007-11-27 5:41:39]

# 1
Easiest way is to define a Servlet that is loaded on startup. (in web.xml)You can put code into the init method of that servlet.This code will run at the time of starting up the server. You can then instantiate the class that you want to.Cheers,evnafets
# 2
Thanx for ur suggestion.But it's a pure java class file to implement
some interface,i used some inbuild methods(execute). FYI to check this site http://www-128.ibm.com/developerworks/library/j-quartz/index.html
From that i tried the crontrigger.java program. How to convert this java
file into servlet class.
# 3
You are trying to integrate Quartz into a servlet container? http://gadjah-mada.blogspot.com/2006/06/opensymphony-quartz-on-tomcat-and.html http://wiki.opensymphony.com/display/QRTZ1/ServletInitScheduler
# 4
The problem is i have to schedule this task n for which I am using Quartz.I did this task in a standalone application using the CronTrigger. But i cant able to implement this job in my web-application(struts).
Somebody help me to get rid of this problem.Can u send me source code
For this problem.
# 5
Anyone can u send me a code for integrating quartz in Struts application.
# 6
evnafets already have given some links. Do I have to copypaste the code from those links into this post?
Furher on, try to ask specific questions: What's the actual problem? What did you have implemented as far? What exactly are you struggling with? Which solutions didn't help? Etcetera. Meaningless statements like "But i cant able to implement this job in my web-application(struts)." are certainly not clear enough to help you further. Asking for source code (with other words: asking us to develop for you) is also not the way.
Or if you expect that we have to take over your development work, talk about it with your boss.
# 7
"SimpleServlet.java"
package com;
import org.quartz.CronExpression;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.CronTrigger;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.HttpServlet;
import org.quartz.ee.servlet.QuartzInitializerServlet;
public class Simple extends HttpServlet {
//Override
public void init(ServletConfig config) throws ServletException {
System.out.println("Initializing Scheduler PlugIn for Jobs!");
super.init(config);
// Retrieve a scheduler from schedule factory
try {
Scheduler scheduler;
SchedulerFactory schedulerFactory = new
StdSchedulerFactory();
scheduler = schedulerFactory.getScheduler();
ServletContext ctx = config.getServletContext();
//Scheduler scheduler = null;
StdSchedulerFactory factory = (StdSchedulerFactory)
ctx.getAttribute(QuartzInitializerServlet.QUARTZ_FACTORY_KEY);
scheduler = factory.getScheduler();
//JobDetail jd = new JobDetail("job1",
"group1",SimpleQuartzJob.class);
JobDetail jd = new JobDetail("job1", "group1",Hello.class);
CronTrigger cronTrigger = new CronTrigger("trigger1","group1");
CronExpression cexp = new CronExpression("0/5 * * * * ?");
//String cronExpr = null;
//cronExpr = getInitParameter("cronExpr");
//System.out.println(cronExpr);
cronTrigger.setCronExpression(cexp);
scheduler.scheduleJob(jd, cronTrigger);
scheduler.start();
System.out.println("Job scheduled now ..");
} catch (Exception e){
e.printStackTrace();
}
}
//Override
public void service(ServletRequest request, ServletResponse
response)throws ServletException, IOException {
PrintWriter pw=response.getWriter();
pw.print("<html> <body> <h1>");
pw.print("Please wait,DataBase Operations is
performing.............");
pw.print("</h1></body></html>");
}
//Override
public String getServletInfo() {
System.out.println("servlet started..");
return null;
}
}
"web.xml"
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<display-name>
Quartz</display-name>
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<display-name>Quartz Initializer Servlet</display-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
</init-param>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>Simple</servlet-name>
<servlet-class>com.Simple</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Simple</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
I tried from this site http://www.oreillynet.com/cs/user/view/cs_msg/86579
but it will not work for me.
It throws servlet exception.
Message was edited by:
SARAV_RS
# 8
> It throws servlet exception.Exceptions are not to be ignored. Share them with us if you don't understand them (try to ask yourself why not).
# 9
i got the exception :
javax.servlet.ServletException: Error instantiating servlet class com.SimpleServlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: org/quartz/Trigger
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
# 10
Look! There is the main cause, it's a NoClassDefFoundError.
First step is to try to understand when and why this exception will be thrown and how to solve it. To start off: the name of the exception almost speaks for itself, the given class cannot be found in the classpath of the running environment. Also see it's API documentation: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/NoClassDefFoundError.html
# 11
In other words, make the required libraries available to your web app.Probably by putting the jar files into the WEB-INF/lib directory.
# 12
Ya, i put the quartz.jar file in lib directory.Now it's working.Classnot found
exception is solved.
Actually i want to integrate Quartz in my struts web application.
i changed the crontrigger.java as a servlet class file.And i specify
the servlet class in my web.xml file.
whether,i need to add anything in struts-config.xml,Can u give me the suggestions.
# 13
Hi experts,
I want to integrate Quartz api in my struts applications.
i tried the sample pgm from this site: http://demo.jgsullivan.com/quartz/index.html
1. In my struts-config.xml
<plug-in className="com.jgsullivan.struts.plugins.QuartzPlugIn" >
<set-property
property="configPath"
value="/WEB-INF/quartz-config.xml"/>
</plug-in>
2. I placed in my WEB-INF/quartz-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE quartz-config SYSTEM "quartz-config.dtd">
<quartz-config>
<!-- Create a Trigger -->
<trigger-group>
<trigger
name="myTrigger"
className="org.quartz.CronTrigger">
<set-property
property="cronExpression"
value="0/30 * * * * ?"/>
</trigger>
</trigger-group>
<!-- Create a Job -->
<job-group>
<job
name="Hello"
className="com.Actions.Hello"/>
</job-group>
<!-- Schedule the Job/Trigger -->
<schedule job="Hello" trigger="myTrigger"/>
</quartz-config>
3. And i added the jar file in my lib directory "jgs-struts-0.2-dev.jar"
My problem is once i start my web-app,
it throws exception,
HTTP Status 404 - Servlet action is not available
type Status report
message Servlet action is not available
description The requested resource (Servlet action is not available) is not available.
Plese give me suggestions,
Thanx in advance,
