一尘不染

无法在基于JHipster的Web应用程序中运行从Gradle BootRepackage生成的战争

spring-boot

我正在尝试使用java -jar产生的war文件./gradlew -Pprod bootRepackage。该bootRepackage任务成功结束。

当我在project_root/build/libs/文件夹中查找时,war和war.original文件将使用以下权限创建:

-rw-rw-r-- 1 user user 110376521 Apr 24 09:42 app-0.1-SNAPSHOT.war
-rw-rw-r-- 1 user user 107542786 Apr 24 09:40 app-0.1-SNAPSHOT.war.original

在我的build.gradle中,我有以下内容:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'spring-boot'
apply plugin: 'war'

bootRepackage {
    mainClass = 'org.package.Application'
}

// Original from JHipster. Uncommenting this does not work either.
//springBoot {
//    mainClass = 'org.package.Application'
//}

// I got this from [this][1] questions, but did not work either.
war {
    baseName = 'app'
    version =  '0.1-SNAPSHOT'
    manifest {
        attributes 'Main-Class': 'org.package.Application'
    }
}

当我运行jar时,我得到:

$ java -jar app-0.1-SNAPSHOT.war --spring.profiles.active=prod
java.lang.IllegalStateException: No 'Start-Class' manifest entry specified in jar:file:/home/user/.../build/libs/app-0.1-SNAPSHOT.war!/
        at org.springframework.boot.loader.archive.Archive.getMainClass(Archive.java:57)
        at org.springframework.boot.loader.ExecutableArchiveLauncher.getMainClass(ExecutableArchiveLauncher.java:63)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:61)
        at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:80)

我该怎么办?谢谢。

更新 我解压了战争,并查看了MANIFEST.MF:

Manifest-Version: 1.0
Start-Class: org.package.Application
Spring-Boot-Version: 1.1.7.RELEASE
Main-Class: org.springframework.boot.loader.WarLauncher

我这个正确吗?


阅读 366

收藏
2020-05-30

共1个答案

一尘不染

这是有效的build.gradle,bootRepackage注释掉了:

buildscript {
    repositories {
        mavenCentral()
                        }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'spring-boot'
apply plugin: 'war'

repositories {
    mavenCentral()
}


dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
}

//bootRepackage {
//    mainClass = 'org.package.Application'
//    }

war {
    baseName = 'app'
    version =  '0.1-SNAPSHOT'
    manifest {
        attributes 'Main-Class': 'org.package.Application'
    }
}

区别于MANIFEST.INF

> libs  diff META-INF/MANIFEST.MF ~/temp/MANIFEST-MF-works 
2c2
< Start-Class: org.package.Application
---
> Start-Class: Application

在行动

> sample        /opt/java/bin/java -jar build/libs/app-0.1-SNAPSHOT.war

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.3.RELEASE)

2015-04-24 18:44:55.443  INFO 18776 --- [           main] Application                              : Starting Application on vagrant-ubuntu-trusty-64 with PID 18776 (started by developer in /home/developer/developments/gradle-sandbox/sample)
2020-05-30