0

I am taking that mistake but I am working to solve the mistake , really I do not know why I am taking error ? In stackoverflow , there is similar of my error . I tried these but it did not work again. I used java 1.8 jdk and spring boot 2.3.2

pom.xml

    <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.javakerem</groupId>
    <artifactId>SpringBootDemoo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>SpringBootDemoo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

SpringBootDemooApplication.java

package com.javakerem.SpringBootDemoo;

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

@SpringBootApplication
public class SpringBootDemooApplication {

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

}

ProductsController.java

package com.javakerem.SpringBootDemoo.apiTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductsController {
    
    @GetMapping("/")
    public String get()
    {
        return "Kerem Kagan";
    }
    
}   

I can write a little english , i am sorry if i wrote false.

Mistake is that :

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
    at com.javacourse.springBootDemo.SpringBootDemoApplication.main(SpringBootDemoApplication.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 1 more
Dok112
  • 1
  • 1
  • 4

1 Answers1

0
  1. cd to THE_PROJECT_FOLDER via the cmd or git bash

    mvn clean
    maven install
    maven package
    
  2. go to the project using your IDE and go to the class containing the main method

  3. Click on the @SpringBootApplication and see to the left an icon like a lamp

  4. Click on it and select download with maven

  5. run the applcation

Try this it may work fine for you

Prateek Kumar
  • 53
  • 1
  • 9
  • I tried these but it did not work again . Do you think is there anything else why it does not work ? Actually , I surprised because I am listening the lesson I am doing the same of teacher I encountered an error. – Dok112 Jul 27 '20 at 17:35
  • No nothing else I ran it in my system it worked fine did you change the version I mentioned above? – Prateek Kumar Jul 27 '20 at 17:40
  • Yes I changed and I made that : I listened my teacher the lesson , I download in there source code , It did not work :) but it worked of my teacher in the lesson. Do you think anything is there else ? – Dok112 Jul 27 '20 at 17:44
  • Show full error trace so that I can guide you more just copy the whole error message shown to you in browser and paste it here in your question – Prateek Kumar Jul 27 '20 at 17:45
  • I edited but my all spring project is same error just group or artifact is different . Error is as above. – Dok112 Jul 27 '20 at 17:52
  • I have edited my answer please check and do let me know if it work for you – Prateek Kumar Jul 27 '20 at 18:04
  • I went my project folder D:\Eclipse2020\springBootDemo in cmd. But how i can write mvn clean in cmd , so what i will write in cmd when i came in my project folder ? – Dok112 Jul 27 '20 at 18:25
  • yes you can write mvn clean as its spring boot project simply do what I have mentioned please check the project location as you have imported the project so it may be in downloads folder of your system – Prateek Kumar Jul 27 '20 at 18:28
  • in your question's title there is com.javacourse.springBootDemo so please tell me whats this as I can't see it in your files so what is this – Prateek Kumar Jul 27 '20 at 18:32
  • D:\Eclipse2020\springBootDemo>mvn clean 'mvn' is not recognized as an internal or external command, operable program or batch file. – Dok112 Jul 27 '20 at 18:37
  • Have you used start.spring.io website for spring boot project if not then use it – Prateek Kumar Jul 27 '20 at 18:39
  • Yes I have used . – Dok112 Jul 27 '20 at 18:42
  • so you have selected the maven project then this command must work view above the person have mentioned other question link see if that helps otherwise do a fresh start means create new project – Prateek Kumar Jul 27 '20 at 18:42