NhutLe
NhutLe

Reputation: 95

Importing project spring-boot in IntelliJ IDEA error

I'm importing spring-boot web maven project in IntelliJ, My project has worked in Eclipse and STS tool. I have an error below:

/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50562:/Applications/IntelliJ 
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/Filter
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more
Process finished with exit code 1

Please help to resolve it. Thanks.

Upvotes: 0

Views: 1074

Answers (1)

Atul Dwivedi
Atul Dwivedi

Reputation: 1462

This usually happens when you forgot to add Servlet related dependencies in your project, specially when you import a project which was built on Eclipse where you have option to attach server(like Apache Tomcat) in project Build Path.

So in new IDE(in your case IntelliJ) also, you have to do the same, but I suggest add the required dependencies then it will work with all IDEs.

Try adding below dependencies in your project pom.xml:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

Dependencies version you can change as per project requirement.

Alternatively if project has spring-boot-starter-tomcat dependency then make sure it should scoped as compile like below:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>compile</scope>
        </dependency>

Upvotes: 1

Related Questions