简体   繁体   中英

How create runnable .jar file in Intellij/Gradle

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

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'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM