[英]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.