Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Could not find main method from given launch configuration" when using Java+Scala+Slick2D

I've got a project in which I'm using Java+Scala+Slick2D.

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:

enter image description here

And if I try to export into just a Jar file, it's unable to find the Main Class:

enter image description here

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: 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.

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

Edit: The Main class is in Java

like image 637
Plasty Grove Avatar asked Nov 23 '12 11:11

Plasty Grove


1 Answers

Okay, I got it to work. Apparently, all I needed to do was restart eclipse. And then magically, it started detecting the Main class:

enter image description here

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.

Then, I fired up JarSplice and added everything as follows:

  1. 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 wellenter image description here
  2. Next, when I tried to "Add Natives" it kept giving me "Duplicate library" error. So I removed them all and kept it empty.
  3. Next in "Main Class", I entered the path to the main class i.e. game.TicTacGame
  4. Finally, "Create Fat Jar". And it works perfectly :)
like image 76
Plasty Grove Avatar answered Sep 21 '22 19:09

Plasty Grove