如何在 Windows 上编译的 Ubuntu 中运行 JAR 文件? [英] How do I run a JAR file in Ubuntu that was compiled on windows?

查看:46
本文介绍了如何在 Windows 上编译的 Ubuntu 中运行 JAR 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 上用 java 1.8 编译了 Java 项目,它在我的 Windows 机器上运行良好,然后在我的 Ubuntu 中我也用 Java 1.8 设置它,现在 Ubuntu 说找不到 Main 类,我研究了这个问题,没有帮助,我怀疑它与文件夹路径有关,但我将 net-beans 编译的整个项目文件夹复制到我的 Ubuntu.我的清单文件内容:

I compiled the Java project on Windows with java 1.8, it worked fine on my windows machine, then in my Ubuntu I set it up with Java 1.8 too, now Ubuntu says can’t find Main class, I researched the problem, didn’t help, I suspect it has something to do with the folder path, but i copied the entire project folder compiled by net-beans to my Ubuntu. my manifest file contents :

清单版本:1.0

X-COMMENT:主类会被构建自动添加

X-COMMENT: Main-Class will be added automatically by build

推荐答案

您的清单文件没有列出主类以及类路径依赖项.所以这意味着当你运行 jar 时,你必须通过提供类路径以及要运行的主程序来运行.

Your manifest file doesn't list the main class as well as the class path dependencies. So that means when you run the jar, you have to run by providing the class path as well as the main program to run.

例如

java -cp/path/to/my/jar/dependencies -jar file.jar com.package.of.my.main.class.MyMainClass "任何参数,如果有的话"

或者让你的清单文件提供类路径和主类,然后运行

Or have your manifest file provide both the class path and the main class and just run

java -jar file.jar

这篇关于如何在 Windows 上编译的 Ubuntu 中运行 JAR 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆