简体   繁体   English

无法运行 jar 文件。 (错误:无法找到或加载主类 co.pissarra.Mainkt)

[英]Unable to run jar file. (Error: Could not find or load main class co.pissarra.Mainkt)

I was trying to create a small webserver using spark and kotlin.我试图使用 spark 和 kotlin 创建一个小型网络服务器。

But I am stuck at the step where I should be able to create a jar of the project and run it from the command line.但是我被困在我应该能够创建项目的 jar 并从命令行运行它的步骤。 But I get the following error on running java -jar pissarra-core-all-1.0-SNAPSHOT.jar但是在运行java -jar pissarra-core-all-1.0-SNAPSHOT.jar出现以下错误

Error: Could not find or load main class co.pissarra.Mainkt

I tried using intellij idea's artifact creation without success, and moved on to creating jar using build.gradle .我尝试使用 intellij idea 的工件创建但没有成功,然后继续使用build.gradle创建 jar。 Following is the code for the same以下是相同的代码

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Version': version,
                'Main-Class': 'co.pissarra.Mainkt'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
} 

After running ./gradlew clean followed by ./gradlew fatJar , I am able to create jar file in build/libs/ directory.运行./gradlew clean然后运行./gradlew clean ./gradlew fatJar ,我可以在build/libs/目录中创建 jar 文件。 This jar also gives the same error.这个 jar 也给出了同样的错误。

On extracting the jar file, I am able to see the directory structure co/pissarra/ with the Mainkt.class file inside it.在解压 jar 文件时,我能够看到目录结构co/pissarra/以及其中的Mainkt.class文件。 Also it has the META-INF directory with MANIFEST.MF file whose content are as follows它还有META-INF目录和MANIFEST.MF文件,其内容如下

Manifest-Version: 1.0
Implementation-Version: 1.0-SNAPSHOT
Main-Class: co.pissarra.Mainkt

Since stackoverflow does not allows to upload files, you can find the jar file here .由于stackoverflow不允许上传文件,你可以在这里找到jar文件。 You can also build the jar file from the github project here .您还可以从此处的 github 项目构建 jar 文件。

Check your MANIFEST file.检查您的清单文件。 The class name should be "MainKt" and not "Mainkt"类名应该是“MainKt”而不是“Mainkt”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法运行jar文件:找不到或加载主类Hello - Cannot run jar file: Could not find or load main class Hello 错误:无法在 Jar 中找到或加载主类 - Error: Could not find or load main class in Jar JavaFX 错误:当我尝试运行我的 Z6849095FCDBF43AD7Z(IntelliJ)文件时,无法找到或加载主 class home.main - JavaFX Error : Could not find or load main class home.main with gradle (IntelliJ) when I try to run my jar file Gradle:即使jar包含正在获取的主类文件错误:无法找到或加载主类 - Gradle : Even though jar contains main class file getting Error: Could not find or load main class 无法使用 gradle 生成的 jar 文件找到或加载主类 - Could not find or load main class with gradle generated jar file Gradle:“错误:无法找到或加载主 class 主”。 通过 Gradle 构建后无法运行文件 - Gradle: "Error: Could not find or load main class Main". Can't run file after build via Gradle 无法使用Gradle运行应用程序:错误:找不到或加载主类1.8 - Unable to run application with Gradle: Error: Could not find or load main class 1.8 无法在Eclipse中使用Gradle运行黄瓜功能文件。 我收到“错误:无法找到或加载主类Cucumber.api.cli.Main”错误 - Unable to run cucumber feature file using gradle in Eclipse. I am getting “Error: Could not find or load main class cucumber.api.cli.Main” error Gradle Run引发“错误:无法找到或加载主类” - Gradle Run throwing “Error: Could not find or load main class” 错误:无法找到或加载主 class org.gradle.wrapper.GradleWrapperMain 并且不存在 gradle-wrapper.jar - Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain and no gradle-wrapper.jar exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM