There are two jar packages commons-fileupload-1.3.2.jar and commons-io-2.5.jar
I initially put these two packages outside like other packages, that is, External Libraries
After writing the relevant classes, configure servlet and mapping in web.xml
<servlet>
<servlet-name>mytest</servlet-name>
<servlet-class>servlet.FileUploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mytest</servlet-name>
<url-pattern>/upload</url-pattern>
</servlet-mapping>
Then Tomcat fails to start, prompting:
Serious: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException
Question:
Do the two jars commons-fileupload and commons-io have to be placed under WEB-INF? Why?
Why can't it be placed in External Libraries? All my other packages can be used in External.
Why can’t these two get in?
I created a new lib under WEB-INF, and then put these two packages into it. It was there when I released it, and then it ran normally.
What is special about these two packages? Why must you put it under WEB-INF
某草草2017-05-17 10:00:05
idea’s tomcat plug-in publishing application is this Artifact
Check whether the Artifact of your current project does not have the jar package it depends on in External Libraries
Then add lib to this Artifact (in the project web/WEB-INF/lib
下放入jar包会自动加到Artifact里面。这就是为什么你说的为什么放到WEB-INF才行的原因。当然你完全可以把依赖jar包还放在External Libraries,在Artifact这里添加上就行,不过还是推荐把依赖的jar包放在项目web/WEB-INF/lib
, put this folder as a jar library in External Libraries)
The dependency problem was solved after starting tomcat
怪我咯2017-05-17 10:00:05
First of all, let me correct you, it is the WEB-INF
directory, not WEB-INFI.
Did you use maven to package the project before publishing? If there is commons-fileupload
的依赖,打包时会放在WEB-INF/lib
in maven.
PHPz2017-05-17 10:00:05
The jar package placed in WEB-INF/lib, even if it is not introduced as a dependency, will be included in the final war package by default (the location is still WEB-INF/lib) when packaging. As for the jar package that is not located under WEB-INF/lib, it needs to be introduced as a dependency before the final war package will be entered during the package (it will still be located in WEB-INF/lib). For the method of introducing dependency, please refer to the answer on the 3rd floor
我想大声告诉你2017-05-17 10:00:05
I have also encountered this problem. I found that the imported Jar was not added to WEB-INF/lib when it was released. I really couldn’t see the corresponding Jar in the Tomcat directory, so I copied and pasted it every time after importing. Under WEB-INF/lib, sometimes even paste directly into Referenced Libraries and WEB-INF/lib without importing.