Export a Jar file with Manifest attribute in Android Studio?

I am trying to start a jar from an Android studio. After a long workaround, the jar file works fine.

Now I need to export the jar file from Android studio. I got the Jar file from the build / libs folder.

But the problem is that the jar file shows an error.

there is no main attribute of the manifest in "app.jar"

So, I found this solution. Cannot execute jar file: "there is no main manifest attribute"

Then I read about MANIFEST.MF and added a mail class to this file.

jar {
    manifest.attributes(
            'Main-Class': "com.Remo.server.RemoServerApp"
    )
}

After adding to my gradle. My MANIFEST.MF contains MainClass.

But am I still getting the same error? How can i solve this?

Note. The goal is that I want to export the Runnable Jar file from the project.

UPDATE:

MainClass MANIFEST.MF. .

Exception in thread "main" java.lang.NoClassDefFoundError: com/Remo/protocol/RemoConnection
    at com.Remo.server.RemoServerApp.<init>(RemoServerApp.java:33)
    at com.Remo.server.RemoServerApp.main(RemoServerApp.java:97)
Caused by: java.lang.ClassNotFoundException: com.Remo.protocol.RemoConnection
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

MANIFEST.MF

-: 1.0
: com.Remo.server.RemoServerApp

2

, remoprotocol jar remoserver.

remoserver gradle

apply plugin: 'java'

sourceSets {
    main {
        resources.srcDirs = ['src/main/resources']
    }
}

dependencies {
    compile project(':remoprotocol')
    compile files('libs/bluecove-2.1.1.jar')
}

jar {
    manifest.attributes(
            'Main-Class': "com.remo.server.remoServerApp"
    )
    manifest.attributes(
            'Class-Path': configurations.runtime.files.collect { it.getName() }.join(' '))
}

task copyRTDependenciesToLib(type: Copy) {
    into "$buildDir/output/lib"
    from configurations.runtime
}

gradle .

+4
2

builddir/libs ( , ). , :

task copyRTDependenciesToLib(type: Copy) {
    into "$buildDir/libs"
    from configurations.runtime
}

Class-Path . , , - . (, )

jar {
    manifest {
        attributes(
           "Main-Class": "com.Remo.server.RemoServerApp",
           "Class-Path": configurations.runtime.files.collect { it.getName() }.join(' '))
         )
    }
}

, :

  • application ; installDist, , readme, , .

  • runnable jar , "fatjar", :

    task fatJar(type: Jar) {
        manifest {
            attributes 'Implementation-Title': 'Gradle Jar File Example',  
                'Implementation-Version': version,
                'Main-Class': "com.Remo.server.RemoServerApp"
        }
        baseName = project.name
    
        //collect all dependencies
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
        with jar
    }
    
+4

Android Studio ( Gradle), Java. ?

Class-Path Main-Class, Main-Class, - JAR.

-1

Source: https://habr.com/ru/post/1622374/


All Articles