我知道这个问题已经被问了一百万遍了,但是我似乎找不到解决它的方法。
问题是,当我使用以下命令运行JAR文件java -jar MYFATJAR.jar
时:
openjdk version "1.8.0_191-1-ojdkbuild"
OpenJDK Runtime Environment (build 1.8.0_191-1-ojdkbuild-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
我收到以下错误:
Error: Could not find or load main class PACKAGE_PATH.MAINCLASSNAME
但是当我使用以下命令运行相同的命令时
java version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)
罐子运行良好。
我使用Gradle编译JAR。这是缩短的build.grade
文件:
// build.gradle
plugins {
id 'java'
id 'application'
}
jar {
manifest {
attributes (
"Main-Class": "org.me.logreader.App",
"Specification-Title": "Log Reader",
"Specification-Vendor" : "ME",
"Implementation-Title" : "Log Reader",
"Implementation-Vendor" : "ME"
)
}
archiveName = "LogReader.jar"
from {
configurations.compile.collect {it.isDirectory() ? it : zipTree(it)}
}
}
...
项目结构如下:
src
-main
-java
-org.me.logreader
-controllers
-model
-parsers
-version
-views
-workers
App.java
更新
MANIFEST.MF
文件的内容:
Manifest-Version: 1.0
Implementation-Title: Log Reader
Specification-Vendor: ME
Specification-Title: Log Reader
Main-Class: org.kobbigal.logreader.App
Implementation-Vendor: ME