gpt4 book ai didi

java - application.jar 中没有主要 list 属性

转载 作者:行者123 更新时间:2023-12-01 19:48:09 31 4
gpt4 key购买 nike

在 CI 环境中使用 spring boot jar 时出现以下错误

java -jar application.jar

no main manifest attribute, in application.jar

奇怪的是,它在我的本地或 Jenkins 奴隶中没有给出问题。一切顺利开始。

当我将 jar 上传到 Nexus artifactory 并将其下载到我的 CI 环境中时,它遇到了问题。

使用构建 jar

gradle clean build -x test

我的 gradle.build 文件

buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
mavenLocal()
mavenCentral()

}
dependencies {
classpath 'org.akhikhl.gretty:gretty:1.2.4'
classpath 'org.ajoberstar:gradle-jacoco:0.1.0'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2'
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE")
}
}

repositories {
mavenCentral()
mavenLocal()
maven {
credentials {
username "hello"
password "world"
}
url "Nexus URL"
}
}

apply plugin: 'maven-publish'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'spring-boot'
apply plugin: "org.sonarqube"
apply plugin: 'jacoco'

group = 'com.company.pod'

/* Determining version from jenkins pipeline, otherwise is set to 1.0.0-SNAPSHOT */
version = new ProjectVersion(1, 0, System.env.SOURCE_BUILD_NUMBER, System.env.RELEASE_TYPE)

println(version)


class ProjectVersion {
Integer major
Integer minor
String build
String releaseType

ProjectVersion(Integer major, Integer minor, String build, String releaseType) {

this.major = major
this.minor = minor
this.build = build
this.releaseType = releaseType
}

@Override
String toString() {
String fullVersion = "$major.$minor"

if(build) {
fullVersion += ".$build"
}
else{
fullVersion += ".0"
}

if(releaseType) {
fullVersion += "-RELEASE"
}
else{
fullVersion += "-SNAPSHOT"
}

fullVersion
}
}

/*Sonarqube linting of your repository.*/
sonarqube {
properties {
property "sonar.language", "java"
}
}


/* Please don't comment out the part below
To run the same on your laptops/prod boxes/CUAT boxes, just edit the gradle.properties file.
(It will be present in the home directory of the user you are using to run gradle with.`sudo` means root user and likewise)
Enter the following lines(and yes, it will run without values, thank you gradle!)

nexusUrl=
nexusRelease=
nexusSnapshot=
nexusUsername=
nexusPassword=

*/

uploadArchives {
repositories {
mavenDeployer {
repository(url: nexusUrl+"/"+nexusRelease+"/") {
authentication(userName: nexusUsername, password: nexusPassword)
}
snapshotRepository(url: nexusUrl+"/"+nexusSnapshot+"/"){
authentication(userName: nexusUsername, password: nexusPassword)
uniqueVersion = false
}
}
}
}






publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}

publishing {
publications {
maven(MavenPublication) {
groupId 'com.company.something'/*This is different from group variable before*/
artifactId 'something'
version '2.0.0'
from components.java
}
}
}

/*
publishing {
repositories {
maven {
url "~/.m2/repository/"
}
}
}
*/

task wrapper(type: Wrapper) {
gradleVersion = '2.9'
distributionUrl = "https://services.gradle.org/distributions/gradle-$GradleVersion-all.zip"
}

dependencies {
compile('org.projectlombok:lombok:1.16.6')
compile("com.company.commons:company-app:0.0.1-RELEASE")
compile group: 'com.google.guava', name: 'guava', version: '19.0'
compile("com.squareup.retrofit2:retrofit:2.0.1")
compile("com.squareup.retrofit2:converter-jackson:2.0.1")

compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7'
compile("com.getsentry.raven:raven-logback:7.2.2")
compile("org.springframework.boot:spring-boot-starter-actuator")

testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("com.h2database:h2")
testCompile("junit:junit")
// testCompile("org.springframework.boot:spring-boot-starter-test")
// testCompile group: 'org.hibernate', name: 'hibernate-validator', version: '4.2.0.Final'
}

查阅文章没有白费 1.Gradle- no main manifest attribute 2.http://www.vogella.com/tutorials/Gradle/article.html#specifying-the-java-version-in-your-build-file 3.Can't execute jar- file: "no main manifest attribute"

最佳答案

默认打包的jar文件不包含MANIFEST文件。我不知道如何在 Gradle 中配置,但是在 Maven 中添加插件时:

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>vn.dung.Application</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>

这对我有用。您可以将该 Maven 插件配置更改为 Gradle。

关于java - application.jar 中没有主要 list 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40846908/

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