0

I followed this "tutorial" to build a jar from a project in intellj. The project includes a small spring application, that works running from intellij itself.

If I build the jar and run it from the command line, it says "Error: Could not find or load main class". If I run the main.class file using java .\main.class, the same Message shows up.

I specified the Main class in Intellij-IDEA before building the Jar, and the Main.java file looks something like this:

@SpringBootApplication
@RestController
public class Main {

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


    @GetMapping("/index")
    public String index() {
           . . . .
    }
}
luk2302
  • 55,258
  • 23
  • 97
  • 137

2 Answers2

1

I performed some test

So I created a new project

enter image description here

I left the default options

enter image description here

test with the intellij build

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

not work enter image description here

not work enter image description here

test with the build provided in spring boot enter image description here

enter image description here

enter image description here

it works enter image description here

Dharman
  • 30,962
  • 25
  • 85
  • 135
Abneco
  • 101
  • 1
  • 8
  • open command prompt, place yourself in the application directory, and run the following command : nvmw package – Abneco Dec 30 '20 at 13:50
  • it still returns Error: Could not find or load main class demo-0.0.1-SNAPSHOT.jar. The build was successful –  Dec 30 '20 at 13:59
  • once the successful configuration is used you do the following command : java -jar .\target\demo-0.0.1-SNAPSHOT.jar -> the name must match the name of the file defined in the pom.xml name+version – Abneco Dec 30 '20 at 14:05
  • ok, thank you! I did some stupid mistakes here, thank you for being so patient! –  Dec 30 '20 at 14:06
0

I forgot to tell you that

you can create an order in intellij

enter image description here

enter image description here

Change configuration and launch the command from Intellij by pressing the play button enter image description here

Abneco
  • 101
  • 1
  • 8