java - Jar 到 Exe - 未找到主类

标签 java jar compilation exe

我用Java做了一个小游戏。 它有大约 5 个不同的类,主类位于 Game.java 中 我将它编译成一个 jar 文件,并使用 manifest.txt 正确执行了所有操作,其中给出了主类所在文件的名称。 该 jar 文件在我的计算机上可以运行,因此我将其转换为 exe 文件并将其发送给其他人。 当我的 friend 尝试运行 exe 文件时,它给他一个错误:

Could not find main class game. Now exiting.

exe 和 jar 文件在我的计算机上工作正常,但在其他计算机上则不然。 我们都运行 Windows 7。 出了什么问题?

最佳答案

我认为除了 lib 文件夹中的 EXE 文件之外,您还需要在应用程序中使用每个库。有趣的是,当 lib 文件丢失时,显示的错误与主类有关,但事实并非如此;)无论如何,我遇到了同样的问题,并通过在 exe 文件旁边包含 lib 文件夹来解决它。这是 net-beans 在 dist 文件夹中生成的 readme.txt 的一部分,可能对您有帮助:

======================== BUILD OUTPUT DESCRIPTION

when you build an Java application project that has a main class, the IDE automatically copies all of the JAR files on the projects classpath to your projects dist/lib folder. The IDE also adds each of the JAR files to the Class-Path element in the application JAR files manifest file (MANIFEST.MF).

关于java - Jar 到 Exe - 未找到主类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15628733/

相关文章:

java - Spring 测试/生产应用程序上下文

java - 尝试执行我的 jar 文件中的文件

java - 我们可以更新已部署服务器中的 jar/war 文件,然后重新加载新的 jar/war 文件吗?

java - Java解释器和编译器规则冲突

linux - haskell 中的 Latexpdf 式功能?

java - 谷歌地图无法正确显示

java - 在 Java 中将数据拟合为非标准化学生 t 分布

java - GAE 数据存储读取性能

java - Ant jar 任务仅包含单个类文件

php - 使用 PHP 将 C++ 编译为二进制文件