简体   繁体   English

如何在Intellij / Gradle中创建可运行的.jar文件

[英]How create runnable .jar file in Intellij/Gradle

Can someone tell me how run .jar file with Intellij and Gradle in cmd? 有人可以告诉我如何使用Intellij和Gradle在cmd中运行.jar文件吗?

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.MF中的路径/ resources / META-INF中

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

Also I try it, in build.gradle 我也在build.gradle中尝试

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

I run this jar file in this way: 我以这种方式运行这个jar文件:

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: 为了运行.jar文件,您必须在gradle构建之后使其可执行(无论intellij如何),请在gradle文件中使用bootRepackage任务

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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