java执行定时任务,在weblogic中部署失败,请大神帮忙看看,谢谢啦!

Robin_Pisces 软件开发工程师  2015-09-06 11:27:39
学习java定时任务,但是报错了,请各位大神帮我看看什么原因,谢谢!
我的代码如下:
1.写一个监听类:MyTaskListener

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.robin.MyTimerTask;

public class MyTaskListener implements ServletContextListener{
private Timer timer = null;
public void contextInitialized(ServletContextEvent event) {
// 在这里初始化监听器
timer = new Timer(true);
System.out.println("定时器已启动");

// 调用MyTimerTask,0表示任务无延迟,5*1000表示每隔5秒执行任务。
timer.schedule(new MyTimerTask(), 0, 5 * 1000);
System.out.println("定时任务已添加");
}

public void contextDestroyed(ServletContextEvent event) {// 在这里关闭监听器,所以在这里销毁定时器。
timer.cancel();
System.out.println("定时器销毁");
}
}

2.写任务类:MyTimerTask

import java.io.IOException;
import java.util.TimerTask;

public class MyTimerTask extends TimerTask {
FileOperation fo = new FileOperation();
public void run() {
try{
fo.createTxtFile();
System.out.println("定时任务已执行完毕");
}catch(IOException e){
e.printStackTrace();
}
}
}

3.在web.xml中设置监听器

<listener>
<listener-class>com.robin.listener.MyTaskListener</listener-class>
</listener>


但是部署在weblogic时,报错了,以下是报错内容:
<2015-9-6 下午11时24分18秒 CST> <Error> <HTTP> <BEA-101371> <There was a failure when processing annotations for application E:\EclipseWorkSpace\Robin\WebContent. Ensure that the annotations are valid. The error is com.robin.listener.MyTaskListener>
<2015-9-6 下午11时24分18秒 CST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "1441553058070" for task "9". Error is: "weblogic.application.ModuleException: [HTTP:101371]There was a failure when processing annotations for application E:\EclipseWorkSpace\Robin\WebContent. Ensure that the annotations are valid. The error is com.robin.listener.MyTaskListener"
weblogic.application.ModuleException: [HTTP:101371]There was a failure when processing annotations for application E:\EclipseWorkSpace\Robin\WebContent. Ensure that the annotations are valid. The error is com.robin.listener.MyTaskListener
at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:732)
at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:188)
at weblogic.application.internal.ExtensibleModuleWrapper.prepare(ExtensibleModuleWrapper.java:83)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:172)
Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: com.robin.listener.MyTaskListener
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Truncated. see log file for complete stacktrace
>
<2015-9-6 下午11时24分18秒 CST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "WebContent-1".>
<2015-9-6 下午11时24分18秒 CST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: [HTTP:101371]There was a failure when processing annotations for application E:\EclipseWorkSpace\Robin\WebContent. Ensure that the annotations are valid. The error is com.robin.listener.MyTaskListener
at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:732)
at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:188)
at weblogic.application.internal.ExtensibleModuleWrapper.prepare(ExtensibleModuleWrapper.java:83)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:172)
Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: com.robin.listener.MyTaskListener
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Truncated. see log file for complete stacktrace
>
<2015-9-6 下午11时24分18秒 CST> <Error> <Console> <BEA-240003> <Administration Console encountered the following error: weblogic.application.ModuleException: [HTTP:101371]There was a failure when processing annotations for application E:\EclipseWorkSpace\Robin\WebContent. Ensure that the annotations are valid. The error is com.robin.listener.MyTaskListener
at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:732)
at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:188)
at weblogic.application.internal.ExtensibleModuleWrapper.prepare(ExtensibleModuleWrapper.java:83)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:172)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:167)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35)
at weblogic.application.internal.flow.ModuleStateDriver.prepare(ModuleStateDriver.java:38)
at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:139)
at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:55)
at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:706)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35)
at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:237)
at weblogic.application.internal.SingleModuleDeployment.prepare(SingleModuleDeployment.java:48)
at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:158)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:207)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:96)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:229)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:747)
at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1216)
at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:250)
at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:171)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:13)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:46)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.lang.ClassNotFoundException: com.robin.listener.MyTaskListener
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)
at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:43)
at weblogic.servlet.internal.AnnotationProcessingManager.processListeners(AnnotationProcessingManager.java:240)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotationsInWebXml(AnnotationProcessingManager.java:203)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotations(AnnotationProcessingManager.java:105)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotations(AnnotationProcessingManager.java:81)
at weblogic.servlet.internal.WebAppModule.processAnnotations(WebAppModule.java:1828)
at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:717)
...全文
488 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
bashoulin 2016-09-27
楼主楼主,你的问题最后是怎么解决的啊,求告知啊
回复
引用 4 楼 shawn551544 的回复:
嗯,是新建项目时,默认生成的。我只有纯Java程序,需要按照你推荐的那样配置吗?
可以试试看,因为weblogic的问题很纠结
回复
Robin_Pisces 2015-09-09
引用 2 楼 shijing266 的回复:
java.lang.ClassNotFoundException: com.robin.listener.MyTaskListener 会不会是包冲突,你发布到weblogic,在项目中加了weblogic.xml么? weblogic配置
嗯,是新建项目时,默认生成的。我只有纯Java程序,需要按照你推荐的那样配置吗?
回复
Robin_Pisces 2015-09-09
引用 1 楼 skgary 的回复:
Caused By: java.lang.ClassNotFoundException: com.robin.listener.MyTaskListener jar包放的不对么?classname/package拼错了?
jar包在WEB-INF/lib下面,package哪里错了?
回复
java.lang.ClassNotFoundException: com.robin.listener.MyTaskListener 会不会是包冲突,你发布到weblogic,在项目中加了weblogic.xml么? weblogic配置
回复
skgary 2015-09-07
Caused By: java.lang.ClassNotFoundException: com.robin.listener.MyTaskListener jar包放的不对么?classname/package拼错了?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-09-06 11:27
社区公告
暂无公告