0

We created jar file with all dependencies using build.gradle. It successfully gets created, with all dependencies and .class files under appropriate directory (e.g. Launch class under com.role.Browse.framework).

But while running the jar getting Error: Could not find or load main

C:\IdeaProjects\launch_app\build\libs>java -jar Launch_App-all-1.0.0.jar
Error: Could not find or load main class com.role.Browse.framework.Launch

Below is the snap of build.gradle

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'

version '1.0.0'

description = ""Launch_App""

sourceCompatibility = 1.8
targetCompatibility = 1.8

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}


//create a single Jar with all dependencies

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File',
                'Implementation-Version': version,
                'Main-Class': 'com.role.Browse.framework.Launch'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar }


//To add this single Jar standard assemble or build task
artifacts {
    archives fatJar
}

I refer some solutions for similar issues, but nothing works for me,

Gradle : Could Not find...

Note: My main class (i.e. Launch ) extends junit.framework.TestCase class and junit libraries are also included in .jar file.

Please, let me know if anything i'm missing here.

sachin007
  • 1
  • 3

1 Answers1

0

Even for me facing the same issue. For my execution after running the jar file execution command java -jar jarfile_name.jar giving no output.

please check few points. Check with the manifest.mf file and see this should have an entry for main class like Main class="class_Name"