最近刚开始学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类找不到。
五月 , :: 下午 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 Files\Java\jre1..0_65\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1..0_65/bin/server;C:/Program Files/Java/jre1..0_65/bin;C:/Program Files/Java/jre1..0_65/lib/amd64;C:\ProgramData\Oracle\Java\javapath;D:\clementine\bin\;D:\software\2013matlab\runtime\win64;D:\software\2013matlab\bin;C:\Program Files\Java\jdk1..0_65\bin;C:\Program Files\Java\jdk1..0_65\jre\bin;D:\HPLoadRunner\strawberry-perl\perl\bin;C:\Program Files (x86)\HP\NV\lib\thirdparty\safenet\LDK\7.0;C:\Program Files (x86)\HP\NV\lib\shunra\snv;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;D:\software\tortoiseSVN\bin;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\\Tools\Binn\;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files (x86)\Autodesk\Backburner\;C:\Program Files\Microsoft SQL Server\\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\\DTS\Binn\;D:\software\eclipse;;.
五月 , :: 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-nio-8080"]
五月 , :: 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
五月 , :: 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-nio-8009"]
五月 , :: 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
五月 , :: 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in ms
五月 , :: 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
五月 , :: 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/8.0.
五月 , :: 下午 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.
五月 , :: 下午 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:)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:)
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) 五月 , :: 下午 org.apache.catalina.core.StandardContext startInternal
严重: One or more Filters failed to start. Full details will be found in the appropriate container log file
五月 , :: 下午 org.apache.catalina.core.StandardContext startInternal
严重: Context [/first] startup failed due to previous errors
五月 , :: 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-8080"]
五月 , :: 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-nio-8009"]
五月 , :: 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in ms
这时候我意识到可能是包没有导进来,于是我倒腾了好久,最后在这里,找到了原因。这个应该要勾上去,不然没有导进来。
可以这么修改:项目右键-->properties-->deploment assembly-->add java build path entries-->next-->Struts2(刚刚新建的user Library)-->finish。
ok,这时候再运行就没问题了。
贴士:
其实修改一下class-path,把WEB-INF lib目录下新建的文件夹也配置一下,这样tomcat自动帮我们生成jar包,这样也可以解决这个问题。