“无法从给定的启动配置中找到主要方法”使用Java + Scala + Slick2D时 [英] "Could not find main method from given launch configuration" when using Java+Scala+Slick2D
问题描述
我有一个项目,我正在使用Java + Scala + Slick2D。
I've got a project in which I'm using Java+Scala+Slick2D.
项目本身在eclipse中启动时运行良好。但是当我尝试制作一个jar文件时,它只是拒绝工作。这是我在尝试将其导出为Runnable jar时遇到的错误:
The project itself runs well when launched from within eclipse. But when I try to make a jar file, it just refuses to work. Here's the error I keep getting when trying to export it as a Runnable jar:
如果我尝试导出只是一个Jar文件,它就无法找到主类:
And if I try to export into just a Jar file, it's unable to find the Main Class:
当然,游戏中有一个主要类.TicTacGame。但它拒绝承认它。我尝试用简单的Hello World项目创建一个可执行文件,它运行正常。它甚至可以检测到主类。为什么Eclipse在这种情况下没有检测到主类?
There is, of course, a main class in game.TicTacGame. But it refuses to acknowledge it. I tried creating an executable with a simple Hello World project and it worked fine. It even detects the main class. Why is Eclipse not detecting the main class in this case?
PS:我也尝试提取创建的.jar文件,编辑manifest.mf文件以添加Main-Class:game.TicTacGame,输入两个新行并重新创建jar。然后它给了我一个损坏的jar文件错误。
PS: I've also tried extracting the .jar file created, editing the manifest.mf file to add the Main-Class: game.TicTacGame, enter two new lines and recreate the jar. Then it gives me a corrupted jar file error.
我在我的智慧结束,并希望在这方面有任何帮助。我正在使用带有Eclipse Juno,Java 1.7和Scala 2.10的Windows 7 x64
I'm at my wits end and would appreciate any help in this regard. I'm using Windows 7 x64 with Eclipse Juno, Java 1.7 and Scala 2.10
编辑:Main类是Java
The Main class is in Java
推荐答案
好的,我得到了它的工作。显然,我需要做的就是重启eclipse。然后神奇地,它开始检测Main类:
Okay, I got it to work. Apparently, all I needed to do was restart eclipse. And then magically, it started detecting the Main class:
但是jar开始为Slick2d,LWJGL和其他库提供noClassDefFound错误。这就是 JarSplice 来救我的地方。我像以前一样导出了项目,包括所有库和资源。
But the jar started giving me noClassDefFound errors for the Slick2d, LWJGL and other libraries. That's where JarSplice came to my rescue. I exported the project as before, with all the libraries and resources.
然后,我启动了JarSplice并添加了以下所有内容:
Then, I fired up JarSplice and added everything as follows:
- 转到Add Jars并添加刚刚通过eclipse创建的project.jar,添加lwjgl.jar,slick.jar和scala-library.jar。 lwjgl和slick应该在您要导入它们的项目lib文件夹中。 scala-library应该在它所说的任何地方都可用。确保你也添加
- 接下来,当我尝试添加原生时,它一直给我重复库错误。所以我将它们全部删除并保持空白。
- 接下来在主类中,我进入了主类的路径,即game.TicTacGame
- 最后,创造脂肪罐。它完美无缺::)
- Go to "Add Jars" and add the project.jar just created through eclipse, add lwjgl.jar, slick.jar and scala-library.jar. lwjgl and slick should be in your project lib folder where you would have imported them. scala-library should be available wherever it says it is. Make sure you add that as well
- Next, when I tried to "Add Natives" it kept giving me "Duplicate library" error. So I removed them all and kept it empty.
- Next in "Main Class", I entered the path to the main class i.e. game.TicTacGame
- Finally, "Create Fat Jar". And it works perfectly :)
这篇关于“无法从给定的启动配置中找到主要方法”使用Java + Scala + Slick2D时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!