最近刚开始学Struts2.0框架。再导入jar包的时候突然心血来潮。为方便区分jar包的功能,于是想在WEB-INF -> lib 目录下想新建一个struts文件夹,以方便分类查看。
像上图这样子。
再去看web Library的时候,那么问题就来了。使用tomcat8.0,本来这里应该会自动生成的。
这里没有,那我就自己新建一个叫做"struts2"的userlibrary。步骤如下:项目右键-->build path-->configure build path-->Libraries选项卡里面->add Library-->User Library-->next-->user Libraries...-->new-->add jars。
这时候就出现:
当我重启服务器的时候,出现了很多NotFoundException异常。(其实我前面写了几个简单的过滤器,所以错误里面提示了这个StrutsPrepareAndExecuteFilter类找不到。
五月 09, 2016 5:35:29 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:Program FilesJavajre1.8.0_65in;C:WINDOWSSunJavain;C:WINDOWSsystem32;C:WINDOWS;C:/Program Files/Java/jre1.8.0_65/bin/server;C:/Program Files/Java/jre1.8.0_65/bin;C:/Program Files/Java/jre1.8.0_65/lib/amd64;C:ProgramDataOracleJavajavapath;D:clementinein;D:software2013matlab untimewin64;D:software2013matlabin;C:Program FilesJavajdk1.8.0_65in;C:Program FilesJavajdk1.8.0_65jrein;D:HPLoadRunnerstrawberry-perlperlin;C:Program Files (x86)HPNVlib hirdpartysafenetLDK7.0;C:Program Files (x86)HPNVlibshunrasnv;C:ProgramDataOracleJavajavapath;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:Program Files (x86)InteliCLS Client;C:Program FilesInteliCLS Client;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;D:software ortoiseSVNin;C:Program FilesMicrosoftWeb Platform Installer;C:Program Files (x86)Microsoft ASP.NETASP.NET Web Pagesv1.0;C:Program Files (x86)Windows Kits8.0Windows Performance Toolkit;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program FilesCommon FilesAutodesk Shared;C:Program Files (x86)AutodeskBackburner;C:Program FilesMicrosoft SQL Server110DTSBinn;C:Program Files (x86)Microsoft SQL Server110ToolsBinn;C:Program Files (x86)Microsoft SQL Server110ToolsBinnManagementStudio;C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEPrivateAssemblies;C:Program Files (x86)Microsoft SQL Server110DTSBinn;D:softwareeclipse;;. 五月 09, 2016 5:35:29 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-nio-8080"] 五月 09, 2016 5:35:29 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 信息: Using a shared selector for servlet write/read 五月 09, 2016 5:35:29 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["ajp-nio-8009"] 五月 09, 2016 5:35:29 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 信息: Using a shared selector for servlet write/read 五月 09, 2016 5:35:29 下午 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 867 ms 五月 09, 2016 5:35:29 下午 org.apache.catalina.core.StandardService startInternal 信息: Starting service Catalina 五月 09, 2016 5:35:29 下午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/8.0.33 五月 09, 2016 5:35:30 下午 org.apache.jasper.servlet.TldScanner scanJars 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 五月 09, 2016 5:35:30 下午 org.apache.catalina.core.StandardContext filterStart 严重: Exception starting filter struts java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1139) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:518) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:499) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4658) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5277) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) 五月 09, 2016 5:35:30 下午 org.apache.catalina.core.StandardContext startInternal 严重: One or more Filters failed to start. Full details will be found in the appropriate container log file 五月 09, 2016 5:35:30 下午 org.apache.catalina.core.StandardContext startInternal 严重: Context [/first] startup failed due to previous errors 五月 09, 2016 5:35:30 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-nio-8080"] 五月 09, 2016 5:35:30 下午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-nio-8009"] 五月 09, 2016 5:35:30 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 782 ms
这时候我意识到可能是包没有导进来,于是我倒腾了好久,最后在这里,找到了原因。这个应该要勾上去,不然没有导进来。
可以这么修改:项目右键-->properties-->deploment assembly-->add java build path entries-->next-->Struts2(刚刚新建的user Library)-->finish。
ok,这时候再运行就没问题了。
贴士:
其实修改一下class-path,把WEB-INF lib目录下新建的文件夹也配置一下,这样tomcat自动帮我们生成jar包,这样也可以解决这个问题。