0
votes

Can someone tell me how run .jar file with Intellij and Gradle in cmd?

I try create manifest file but get errors:

no main manifest attribute, in eureka-server.jar

or

Error: Could not find or load main class com.project.EurekaServerApplication
Caused by: java.lang.ClassNotFoundException: com.project.EurekaServerApplication

My main class:

package com.project;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

In MANIFEST.MF in path /resources/META-INF

Manifest-Version: 1.0
Main-Class: com.project.EurekaServerApplication

Also I try it, in build.gradle

jar {
    manifest {
        attributes(
                'Main-Class': 'com.project.EurekaServerApplication'
        )
    }
}

I run this jar file in this way:

java -jar [nameApplication].jar
1
This is SpringBoot application you should run it with gradle bootRun command not from a .jar fileAnte Jablan Adamović
Ok, but I need this jar file then to create docker container and get the same error. This solution help me?strinx
Do you want to know how to run .jar (question text) or how to create one (title)?user8840479
How create that run without error.strinx

1 Answers

0
votes

In order to run the .jar file you have to make it executable after the gradle build (regardless of intellij), use the bootRepackage task in your gradle file:

bootRepackage {
  mainClass = 'com.project.EurekaServerApplication'
}