做定时器时的监听器 报错 严重: Error configuring application listener of class test.timer.Time

xxxxxxbin 2011-08-05 11:24:38
直接上代码吧,高手们帮我看看
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

<listener>
<listener-class>test.timer.TimerListener</listener-class>
</listener>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


package test.timer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class TimerListener implements ServletContextListener {

@SuppressWarnings("unused")
private ServletContext servletContext = null;
private Timer timer = null;

/**
* 开始执行
*/
@Override
public void contextInitialized(ServletContextEvent e) {
e.getServletContext().log("init !");
timer = new Timer(true);
// 获得当天的日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
Date date = new Date();
// 定义开始时间字符串
String timeStr = "12:00:00";
timeStr = sdf.format(date) + timeStr;
// 获得当天的指定时间的date对象
sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
date = sdf.parse(timeStr);
} catch (ParseException e1) {
e1.printStackTrace();
}

// 判断今天的执行时间是否已经过去,如果过去则改为明天
if (date.getTime() < System.currentTimeMillis()) {
date = new Date(date.getTime() + 24 * 60 * 60 * 1000);
}

timer.schedule(new TestTimer(), date, 24*60*60 * 1000);

}

/**
* 销毁
*/
@Override
public void contextDestroyed(ServletContextEvent e) {
timer.cancel();
e.getServletContext().log("destroyed");
}
}

环境没有问题,如果web.xml去掉<listener>可以正常启动。项目就这么几个文件
...全文
745 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
love_jiangyijun 2012-07-30
  • 打赏
  • 举报
回复
楼主。。能否具体说一下哪个路径的问题。。小弟也碰到了这个问题。。很是蛋疼。。。
songdz12 2012-03-09
  • 打赏
  • 举报
回复
什么路径问题啊,说的详细点呗
xxxxxxbin 2011-08-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 djyy3273 的回复:]
引用 4 楼 xxxxxxbin 的回复:
没人回复啊,惨了。不过自己解决了。


楼主,错误原因是什么?可否告知!
[/Quote]
路径问题。呵呵,改了就可以了。
大灰兔 2011-08-11
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 xxxxxxbin 的回复:]
没人回复啊,惨了。不过自己解决了。
[/Quote]

楼主,错误原因是什么?可否告知!
xxxxxxbin 2011-08-11
  • 打赏
  • 举报
回复
没人回复啊,惨了。不过自己解决了。
xxxxxxbin 2011-08-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xxxxxxbin 的回复:]
错误信息如下
2011-8-5 11:19:54 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found o……
[/Quote]
昨天还可以跑的,今天就挂了,有些郁闷
大灰兔 2011-08-05
  • 打赏
  • 举报
回复
试了一下,可以启动.你这个错误是java.lang.ClassNotFoundException: test.timer.TimerListener
啊,你把项目重新编译,然后在web服务器上重新发布下.
xxxxxxbin 2011-08-05
  • 打赏
  • 举报
回复
错误信息如下
2011-8-5 11:19:54 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\jdk 1.6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\jdk 1.6\jre\bin;D:/jdk 1.6/bin/client;D:/jdk 1.6/bin;D:/jdk 1.6/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\jdk 1.6\bin;D:\apache-tomcat-6.0.32\bin;C:\Program Files (x86)\Microsoft SQL Server\80\Tools\Binn\;D:\SQL 2005\Microsoft SQL Server\90\DTS\Binn\;D:\SQL 2005\Microsoft SQL Server\90\Tools\binn\;D:\SQL 2005\Microsoft SQL Server (x86)\90\Tools\binn\;D:\SQL 2005\Microsoft SQL Server (x86)\90\DTS\Binn\;D:\SQL 2005\Microsoft SQL Server (x86)\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Common Files\Thunder Network\KanKan\Codecs;D:\mysql\mysql 64\bin
2011-8-5 11:19:54 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-81
2011-8-5 11:19:54 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 882 ms
2011-8-5 11:19:54 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2011-8-5 11:19:54 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.32
2011-8-5 11:19:54 org.apache.catalina.core.StandardContext listenerStart
严重: Error configuring application listener of class test.timer.TimerListener
java.lang.ClassNotFoundException: test.timer.TimerListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4148)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
2011-8-5 11:19:54 org.apache.catalina.core.StandardContext listenerStart
严重: Skipped installing application listeners due to previous error(s)
2011-8-5 11:19:54 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2011-8-5 11:19:54 org.apache.catalina.core.StandardContext start
严重: Context [] startup failed due to previous errors
2011-8-5 11:19:54 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-81
2011-8-5 11:19:55 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2011-8-5 11:19:55 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/62 config=null
2011-8-5 11:19:55 org.apache.catalina.startup.Catalina start
信息: Server startup in 529 ms

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧