0

I am struggling to set up the spring boot project that i have imported in intelliJ IDEA 2016 1.4. Every time i run . I get the below Exception:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
        at com.patientConnect.DemoApplication.main(DemoApplication.java:24)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
    Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 6 more

My gradle settings (linked gradle projects,user gradle wrapper ) all looks good.

package com.Demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public DemoApplication() {
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }


}

build.gradle:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE'
        classpath 'gradle.plugin.com.jamesward:atom-gradle-plugin:0.0.1'
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'    

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-parent:1.5.4.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-devtools'
    compile 'org.springframework.boot:spring-boot-starter-security'
    compile 'org.springframework.security.oauth:spring-security-oauth2'

    compile 'org.apache.httpcomponents:httpclient'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'org.postgresql:postgresql'
    compile 'org.springframework.boot:spring-boot-starter-jdbc'
    compile 'org.hibernate:hibernate-entitymanager'


}

allprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}



import org.gradle.internal.os.OperatingSystem

task devClasses(type: Exec) {
    if (OperatingSystem.current().isWindows())
        commandLine 'gradlew', '-t', 'classes'
    else
        commandLine './gradlew', '-t', 'classes'
}

task devBootRun(type: Exec) {
    if (OperatingSystem.current().isWindows())
        commandLine 'gradlew', 'bootRun'
    else
        commandLine './gradlew', 'bootRun' //, '--debug-jvm'
}

import java.util.concurrent.*

task dev() << {
    def devClassesFuture = Executors.newSingleThreadExecutor().submit({ devClasses.execute() } as Callable)
    def devBootRunFuture = Executors.newSingleThreadExecutor().submit({ devBootRun.execute() } as Callable)
    devClassesFuture?.get()
    devBootRunFuture?.get()
}


task stage {
    dependsOn build
}
Fakeer
  • 165
  • 1
  • 5
  • 17

1 Answers1

0

Try deleting your SpringBoot dependency on your computer.

It will be located at ~/.gradle/caches/modules-2/files-2.1/org.springframework.boot Assuming you kept your gradle dependencies in the default location.

rm -rf ~/.gradle/caches/modules-2/files-2.1/org.springframework.boot

or to delete all dependencies (Just to be sure if no other dependencies is corrupted)

rm -rf ~/.gradle/caches/modules-2/files-2.1/*

then to re-download

gradle build --refresh-dependencies
XPLOT1ON
  • 2,994
  • 2
  • 20
  • 36
  • tried it . Did not work. Still the same issue :( – Fakeer Jul 21 '17 at 15:05
  • Does it produce the same error if you compile jar through command line? `gradle build` – XPLOT1ON Jul 21 '17 at 15:54
  • when i do gradlew build . its successful. But when i do gradlew bootrun from command line it give the same again – Fakeer Jul 21 '17 at 16:40
  • tried https://stackoverflow.com/questions/42587487/noclassdeffounderror-after-intellij-idea-upgrade fix. its not working – Fakeer Jul 21 '17 at 16:55
  • Hmm that narrow the problem down. Can you post your main class (although I don't think the cause is in there), your build.gradle. Also can you try creating a sample test project using this website https://start.spring.io and add some dependencies such as DevTools (SpringBoot), Web etc. make sure you use the site to generate Gradle project and try running it with intellij – XPLOT1ON Jul 21 '17 at 16:56
  • can you also try updating intellij to v. 2017.1 or 2016.3.6? – XPLOT1ON Jul 21 '17 at 16:59
  • Main Class:package com.Demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public DemoApplication() { } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } – Fakeer Jul 21 '17 at 17:01
  • The main class looks fine – XPLOT1ON Jul 21 '17 at 17:02
  • i have edited my question to add main class and build.gradle to it. Also i have tried creating project from the scratch and that is working. In the meanwhile i will try to upgrade to intellij 2017. – Fakeer Jul 21 '17 at 17:14
  • Even with intellij 2017 Community edition getting the same error :( – Fakeer Jul 21 '17 at 17:37
  • I tried it on STS also . Same error. But cant figure out the reason. Any help please? – Fakeer Jul 22 '17 at 17:06