N
N
Nikolay Baranenko2018-11-18 14:06:54
Java
Nikolay Baranenko, 2018-11-18 14:06:54

How to solve the problem with missing main class error?

Hello.
Wrote a Java class to connect to Hive and made a task to build

task Hive(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',
                'Implementation-Version': version,
                'Main-Class': 'ru.prometheus.nodeexporters.Hive'
    }
    baseName = project.name + '-Node_Exporter'
//    from('src/main/java') {
//        include 'resources/*'
//    }
    from {
        configurations.runtime.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    with jar
}

started the build
12:55:46: Executing task 'Hive'...


> Task :Hive:compileJava
Note: C:\Servers\Repository\PrometheusNodeExporters\Hive\src\main\java\ru\prometheus\nodeexporters\Hive.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Servers\Repository\PrometheusNodeExporters\Hive\src\main\java\ru\prometheus\nodeexporters\Hive.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :Hive:processResources
> Task :Hive:classes
> Task :Hive:Hive

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 26s
3 actionable tasks: 3 executed
12:56:13: Task execution finished 'Hive'.

as a result, all classes are in place, including main
5bf1455bbf925750949912.png
BUT when starting Java, the machine cannot find the main class
c:\Servers\Repository\PrometheusNodeExporters\Hive\build\libs>java -jar Hive-Nod
e_Exporter-1.0-SNAPSHOT.jar
Error : Could not find or load main class ru.prometheus.nodeexporters.Hive
project on github
How to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay Baranenko, 2018-11-19
@drno-reg

the problem was that when adding well-defined dependencies, in particular
, LIST files are added and the JVM begins to experience difficulties in determining the main classes
, therefore, in the task, to solve this problem, you need to add:

exclude("META-INF/*.LIST","META-INF/*.SF","META-INF/*.DSA","META-INF/*.RSA")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question