-2

I have created a Spring Boot application, I have build the project and selected the main class and I have also added properties in my pom.xml:

<properties>
        <java.version>1.8</java.version>
        <start-class>com.mua.scraper.ScraperApplication</start-class>
    </properties>

Now the problem is when I try to run the .jar file, it tell me that MainClassNotFound. Here is a snap:

main class not found - spring boot

Later project will be opend here

After changing the command, here is my output:

no main artifact

Error:

No main artifact

Maifee Ul Asad
  • 3,992
  • 6
  • 38
  • 86

2 Answers2

2

You are missing -jar to properly run the jar file. It should be:

java -jar scrapper.jar
pepevalbe
  • 1,340
  • 6
  • 18
  • And use `./mvnw package` to generate an executable jar instead of `./mvnw jar:jar`. – azizunsal Nov 07 '19 at 08:52
  • @azizunsal can you describe a little please ? – Maifee Ul Asad Nov 07 '19 at 13:25
  • It is needed to run `./mvnw spring-boot:repackage` to create an executable jar indeed. Since you added the `execution` goal under `build` plugin, `repackage` is applied after Maven `package` phase. So the resulting jar is an executable one (*the fat jar*), and you can run it by typing `jar -jar target/scrapper.jar`. – azizunsal Nov 08 '19 at 07:09
0

Actually the problem was in my artifact, so here is what I have done:

  • Opened Project Structure(CTRL+ALT+SHIFT+S)
  • Navigate to Artifacts -> JAR -> From module with dependencies
  • Then Selected Main class, or the entry class
  • Copy the output directory and link via manifest(I made the mistake here)
  • Don't forget to select that directory as in the picture

step 1,2-spring build jar

step 3,4-spring build jar

Maifee Ul Asad
  • 3,992
  • 6
  • 38
  • 86