Exporting Jar file with Manifest attribute in Android Studio?

user3467240

I am trying to run a jar from Android studio. After a long Workaround, the jar file run perfectly.

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

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

no main manifest attribute, in "app.jar"

So i found this solution. Can't execute jar- file: "no main manifest attribute"

Then i read about MANIFEST.MF & added the mail class to that file.

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

After adding those in my gradle. My MANIFEST.MF contains the MainClass.

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

Note: The objective is that I want to Export a Runnable Jar file from the project.

UPDATE:

After Adding the MainClass in MANIFEST.MF. I got stuck with the below error.

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

Manifest-Version: 1.0
Main-Class: com.Remo.server.RemoServerApp

UPDATE 2

From your solution what i understood is that we need to copy the remoprotocol jar file to the remoserver.

remoserver project gradle file

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
}

After running the gradle task also i am getting the same error.

RaGe

First you want to copy all your runtime dependencies into the builddir/libs folder (or a different distribution folder if you so choose). Here is a custom task that would achieve this:

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

Add your runtime dependency jars as a Class-Path attribute in your manifest file. The jars need to be in the same directory as your runnable jar - which the copy task above achieves. (alternatively, you can provide full relative path for your dependency jar location)

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

Some more things to consider:

  • The application plugin does the same thing; it adds a task installDist that produces a runnable set of jars along with any dependencies, any readme's, documentation you want to include.

  • If you want to produce a single runnable jar without having to bundle dependencies along with it, you should look into creating a "fatjar", for example:

    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
    }
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JAR file manifest does not contain permission attribute

From Dev

Android Studio exporting Android library project as jar

From Dev

no main manifest attribute (But I have the manifest file in the jar)

From Dev

What is android:immersive attribute in Android manifest file?

From Dev

Failing to run jar file from command line: “no main manifest attribute”

From Dev

Java can't execute jar file no main manifest attribute

From Dev

"no main manifest attribute" after downloading a .jar file in Java

From Dev

Exporting A Libgdx Game as Executable Jar from Android Studio

From Dev

android studio - gradle manifest file path

From Dev

Java jar - no main manifest attribute

From Dev

.jar file not generating in android studio

From Dev

Where is the graphical editor for the Android Manifest file located in Android Studio 1.5.1?

From Java

Fat JAR not working. "No Main Manifest Attribute". Tried POM file, still failing

From Dev

SecurityException during executing jnlp file (Missing required Permissions manifest attribute in main jar)

From Dev

How to produce a jar file for existing maven project without (no main manifest attribute)?

From Dev

Confusion on Uses of Jar Manifest File

From Dev

Manifest Merge in Android Studio

From Dev

Manifest permission in Android Studio

From Dev

Android studio manifest issue

From Dev

No main manifest attribute, in gdx-setup.jar

From Dev

No main manifest attribute, in server.jar

From Dev

Run java jar - no main manifest attribute error

From Dev

openshift: no main manifest attribute in jar maven project

From Dev

Creating Jar with Intellij 2016 - No main manifest attribute

From Dev

Android Studio Gradle Invalid file Manifest.xml

From Dev

Android manifest attribute not allowed here

From Dev

Android Studio preDexDebug After Adding jar File

From Dev

how to create a jar file from android studio

From Dev

How to add any jar file in the Android studio?

Related Related

  1. 1

    JAR file manifest does not contain permission attribute

  2. 2

    Android Studio exporting Android library project as jar

  3. 3

    no main manifest attribute (But I have the manifest file in the jar)

  4. 4

    What is android:immersive attribute in Android manifest file?

  5. 5

    Failing to run jar file from command line: “no main manifest attribute”

  6. 6

    Java can't execute jar file no main manifest attribute

  7. 7

    "no main manifest attribute" after downloading a .jar file in Java

  8. 8

    Exporting A Libgdx Game as Executable Jar from Android Studio

  9. 9

    android studio - gradle manifest file path

  10. 10

    Java jar - no main manifest attribute

  11. 11

    .jar file not generating in android studio

  12. 12

    Where is the graphical editor for the Android Manifest file located in Android Studio 1.5.1?

  13. 13

    Fat JAR not working. "No Main Manifest Attribute". Tried POM file, still failing

  14. 14

    SecurityException during executing jnlp file (Missing required Permissions manifest attribute in main jar)

  15. 15

    How to produce a jar file for existing maven project without (no main manifest attribute)?

  16. 16

    Confusion on Uses of Jar Manifest File

  17. 17

    Manifest Merge in Android Studio

  18. 18

    Manifest permission in Android Studio

  19. 19

    Android studio manifest issue

  20. 20

    No main manifest attribute, in gdx-setup.jar

  21. 21

    No main manifest attribute, in server.jar

  22. 22

    Run java jar - no main manifest attribute error

  23. 23

    openshift: no main manifest attribute in jar maven project

  24. 24

    Creating Jar with Intellij 2016 - No main manifest attribute

  25. 25

    Android Studio Gradle Invalid file Manifest.xml

  26. 26

    Android manifest attribute not allowed here

  27. 27

    Android Studio preDexDebug After Adding jar File

  28. 28

    how to create a jar file from android studio

  29. 29

    How to add any jar file in the Android studio?

HotTag

Archive