我正在尝试使用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)
我该怎么办?感谢。
更新 我解开了战争并调查了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
我这是对的吗?
答案 0 :(得分:2)
这是有效的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)