Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find or load main class, after build by gradle

I've made a project in maven and spring boot. After build it via maven it worked perfect. After all I decided to swap my project into gradle. And now, after:

gradle build

The following exception is comming.Error:

Error: Could not find or load main class

Here are things I checked before I asked this question:

  • made sure that I have main method (which i obviously have, maven did thing great)
  • checked path to main class in manifest and in jar task in gradle
  • found out that compiled class is in specified jar in specified path
  • Made a jar task in gradle that looks like this:

    jar {
      manifest {
        attributes 'Main-Class': 'pl.sygnity.schedulein.App'
      }
    }
    

I have no idea what i can do more about it. Could you help me?

Edit. It's important i wish to use my program as jar so:

java -jar xx.jar

Edit2.

gradle run

makes my App start. So it looks like as if gradle build is not working somehow...

like image 721
iwannabeprogrammer Avatar asked Sep 14 '25 06:09

iwannabeprogrammer


1 Answers

You need to define the main class in the build.gradle file. (You may have more than one, and you need to choose which one to use)

I like to do it with Gradle - the application plugin

apply plugin: 'application'
mainClassName = "<Your main class>"

Then you can run gradle install to build the program with an executor.

like image 186
Roee Gavirel Avatar answered Sep 16 '25 19:09

Roee Gavirel