java 创建 JAR 文件并在 Raspberry PI 上运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17920611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a JAR file and running on Raspberry PI
提问by Mohammed Irfan
This is a very common question and there are chances that this might be marked as Duplicate, but even after reviewing a lot of answers and posts from stackoverflow and other communities, the problem just doesn't solve.
这是一个非常常见的问题,有可能会被标记为重复,但即使在查看了来自 stackoverflow 和其他社区的大量答案和帖子之后,问题也没有解决。
I have created a Project in my NetBeans IDE 7.3 and I Build the Project to get the JAR file by pressing SHIFT+F11. The next step, I perform is through WinSCP I copy the JAR file from my Windows Machine to the directory (/home/pi) in Raspberry PI. Now, I am in the directory in my Raspberry PI where the JAR file is present and in the terminal I run the command
我在 NetBeans IDE 7.3 中创建了一个项目,并通过按 SHIFT+F11 构建该项目以获取 JAR 文件。下一步,我执行的是通过 WinSCP 我将 JAR 文件从我的 Windows 机器复制到 Raspberry PI 中的目录 (/home/pi)。现在,我位于 Raspberry PI 中存在 JAR 文件的目录中,并在终端中运行命令
java -jar ProjectFinal.jar
I get the error "Could not find or load main class".
我收到错误“无法找到或加载主类”。
The contents of my JAR are as shown below (in the form of directories): lib (contains all the libraries) META-INF (contains a MANIFEST.MF file and the contents looks fine) and the contents are shown below:
我的JAR的内容如下图(以目录的形式):lib(包含所有库)META-INF(包含一个MANIFEST.MF文件,内容看起来不错),内容如下图:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_17-b02 (Oracle Corporation)
Class-Path: lib/super-csv-2.1.0.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: projectfinal.ProjectFinal**
and finally projectfinal (contains all the class files). I tried to change the contents of the MANIFEST.MF file by following this link. But this couldn't help me either. Please suggest me any ideas that could get me out of this. It could be really helpful. I can share the code if it is needed. I am using JRE version 7. Any questions/inputs/ideas is deeply appreciated.
最后是 projectfinal (包含所有类文件)。我尝试按照此链接更改 MANIFEST.MF 文件的内容。但这也帮不了我。请给我建议任何可以让我摆脱困境的想法。它可能真的很有帮助。如果需要,我可以共享代码。我正在使用 JRE 版本 7。非常感谢任何问题/输入/想法。
Please help.
请帮忙。
Thanks a lot in advance.
非常感谢。
回答by Sw4Tish
I don't know about NetBeans but Eclipse IDE has an option to export into a "Runnable JAR File" instead of a normal JAR file.
I had the same issue and it solved my problem.
我不了解 NetBeans,但 Eclipse IDE 可以选择导出到“可运行的 JAR 文件”而不是普通的 JAR 文件。
我有同样的问题,它解决了我的问题。
回答by Juned Ahsan
If not then follow this:
如果没有,请按照以下步骤操作:
The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
文本文件必须以换行或回车结束。如果最后一行没有以新行或回车结束,则不会正确解析。