本文实例为大家分享了java项目启动时执行指定方法,供大家参考,具体内容如下
想到的就是监听步骤如下:
1.配置web.xml
<listener> <listener-class>com.listener.initlistener</listener-class> </listener>
2.编写initlistener类
package com.listener; import java.io.file; import javax.servlet.servletcontextevent; import javax.servlet.servletcontextlistener; import com.seegot.util.propertyutil; public class initlistener implements servletcontextlistener { @override public void contextdestroyed(servletcontextevent arg0) { // todo auto-generated method stub } @override public void contextinitialized(servletcontextevent arg0) { // todo auto-generated method stub system.out.println("================>[servletcontextlistener]自动加载启动开始."); string resourcefilespath = propertyutil.getproperty("tempzippath"); clearfiles(resourcefilespath); } // 删除文件和目录 private static boolean clearfiles(string workspacerootpath) { file file = new file(workspacerootpath); if (file.exists()) { deletefile(file); } // resources 文件夹被删除后需新建 if (!file.exists() && workspacerootpath.endswith("resources")) { return file.mkdir(); } else if (!file.exists()) { return true; } return false; } private static boolean deletefile(file file) { if (file.isdirectory()) { file[] files = file.listfiles(); for (int i = 0; i < files.length; i++) { deletefile(files[i]); } } return file.delete(); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
3DV(读书笔记)3DV: 3D Dynamic Voxel for Action Recognition in Depth Video
ExceptionConverter: java.io.IOException
网友评论