我用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/