gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:20:11 25 4
gpt4 key购买 nike

我正在尝试使用 java -jar 运行由 ./gradlew -Pprod bootRepackage 生成的 war 文件。 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)

我该怎么办?谢谢。

更新我解压了 war 并查看了 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

这对吗?

最佳答案

这是有效的 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)

关于java - 无法在基于 JHipster 的 Web 应用程序中运行从 Gradle BootRepackage 生成的 war ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29848088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com