When adding libraries via maven, I get the error NoClassDefFoundError . When adding a jar to WEB-INF / lib, everything works fine.

Problems arise for example with the libraries commons-fileupload-1.3.1, commons-io-2.4, jstl-1.2.

I use:

  • Intellij idea 2016.3,
  • maven.apache.org/POM/4.0.0,
  • Tomcat 8.5.9,
  • springframework 4.3.1.RELEASE

Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [controller.FileUploadController]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org / slf4j / LoggerFactory

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>UploadMultiFiles</groupId> <artifactId>UploadMultiFiles</artifactId> <version>1.0-SNAPSHOT</version> <build> <filters> <filter>config/application.properties</filter> </filters> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.0.0</version> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.3.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.3.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.3.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>4.3.1.RELEASE</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.21</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency> </dependencies> 

  • Show your pom.xml. Most likely the problem is in the settings of the plugin for the assembly. - Mikhail Vaysman
  • @Mikhail Vaysman added in question - makson
  • You collect your jar no dependencies. Naturally, when runtime tries to use one of them, it does not find it. - etki
  • @Etki did not help, I get Servlet.init() for servlet dispatcher threw exception because of this error. corrected pom in question after changes - makson
  • Did not help what? You still collect without addictions. The more traditional way, as far as I understand it, is to throw dependencies into / lib in tomcat, but never use this method. - etki

1 answer 1

In order for the assembly of the WAR file to automatically add all dependencies to the WEB-INF/lib resulting file, you need to indicate in the POM file that you want to assemble the WAR by adding the line:

 <packaging>war</packaging>