简体   繁体   中英

No main manifest attribute in .jar file

I've been looking at several different threads, and found no solution. I have made a project, which retrives data from google sheets, using java and gradle. I have created an artifact and built the jar file through intelliJ. When i try to run the jar through the terminal using "java -jar filename.jar" i get "no main manifest attribute, in filename.jar"

My MANIFEST.MF is located in main/java/META-INF and has the following simple structure

Manifest-Version: 1.0
Main-Class: Main

The build.gradle file has the following structure:

plugins {
    id 'java'
}

group  'filename'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'com.google.api-client:google-api-client:1.30.4'
    compile 'com.google.oauth-client:google-oauth-client-jetty:1.30.4'
    compile 'com.google.apis:google-api-services-sheets:v4-rev581-1.25.0'
}

Clearly i have stated in what class the main method is, and this is why this errormessage, makes no sense to me. Does anyone have a solution for this?

I have followed the steps from the Sheets API quickstart to set up the application. After that, I followed the steps from this other answer to generate the.jar file, that explains that you should declare your manifest file inside your build.gradle file within the jar property.

After this, when running the generated.jar file I got an “Invalid signature file” error which I was able to fix by adding the below line in the jar property as explained here :

exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'

After generating the.jar file you can find it in the build/libs directory of your project. My end build.gradle file looks like this:

apply plugin: 'java'
apply plugin: 'application'

group 'egs'
version '1.0-SNAPSHOT'

mainClassName = 'SheetsQuickstart'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'com.google.api-client:google-api-client:1.30.4'
    compile 'com.google.oauth-client:google-oauth-client-jetty:1.30.4'
    compile 'com.google.apis:google-api-services-sheets:v4-rev581-1.25.0'
}

jar {
    manifest {
        attributes 'Main-Class': 'SheetsQuickstart'
    }
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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