Java 尝试 运行 fxml 时找不到或加载主程序 class

Java Could not find or load main class when trying to run fxml

当我尝试 运行 在 windows 的 netbeans 上编译的 jar 文件时,在 linux rasbian 机器上一切顺利,当我尝试 运行一个fxml jar文件返回如下问题
"Could not find or load main class when trying to run 'classname' " 一切都是 运行 作为同一文件夹中的根,但只有 fxml jar 没有 运行!

编辑 1
我使用标准的 netbeans 设置来构建它



编辑 2
有问题的 jar 的内容(在 notepad++ 中所有行都以 CR LF 结尾)

Manifest-Version: 1.0
Implementation-Title: raspTest
Implementation-Version: 1.0
Permissions: sandbox
Codebase: *
JavaFX-Version: 8.0
Class-Path: 
Created-By: JavaFX Packager
Implementation-Vendor: AXANO
Main-Class: rasptest.RaspTest


工作 jar 的内容

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_66-b17 (Oracle Corporation)
Class-Path: 
X-COMMENT: Main-Class will be added automatically by build
Main-Class: rasp.Rasp



编辑 3
在 linux 中安装了 netbeans,当我在 linux 中 运行 一个 fxml 应用程序时,它 运行 没问题,但是当我尝试 运行 它作为一个带有 java -jar name.jar 我得到同样的错误 "Could not find or load main class..."

你能检查一下你的清单是否正确吗?

在某些情况下,windows 和 linux 不使用同一行 return 格式。 Windows 使用:\r\n 和 Linux 使用:\n

希望对您有所帮助

您需要在项目中指定主要class。您可以这样做:

  1. 右键单击项目并选择属性。
  2. 从右侧的菜单中选择 运行。
  3. 查看MainClass,点击左侧的浏览
  4. 导航至主 class 并按 select 主 class。