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

9

10

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

Exemplificative answered 23/11, 2012 at 11:9 Comment(2)
You might want to add the information whether your main class is a Java or Scala class. I'm not familiar with Eclipse Jar Export, but if I remember correctly, there was some issue that the main class must be a Java class.Solvable
It's a Java main class. Added that in.Exemplificative
E
12

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 :)
Exemplificative answered 23/11, 2012 at 12:42 Comment(3)
Do you have any ideas on why restarting works? It is infuriating that you have to do these weird hacks in eclipse just to get it working half the time...Yockey
No idea, I'm guessing this feature is not very high on their priority list. But to be fair, it at least works. I'm not sure if I would even consider doing this via the command lineExemplificative
certainly. It's just annoying to have to restart eclipse every time you want to do this (it stops working for me after a few times of doing this anyway). +1, by the way :-)Yockey
L
9

I just encountered the same problem, and here is how I solved it:

  1. Open "Run As" --> "Run Configuration" on the project you want to export

  2. Click "Search" for Eclipse to refresh the list of main class

  3. Then export Runnable JAR file again, and everything goes smoothly.

Lockwood answered 29/7, 2013 at 6:30 Comment(0)
C
1

The most easiest method is run the java file once and automatically the file appears in the list.Even i was facing the error but it was solved by using this simple method.

Cabotage answered 15/6, 2020 at 6:33 Comment(0)
C
0

I recently figured a better way to do this using 'Runnable jar export' which might help you. In order for your main method to be listed in that list, you need to add the main method to the Run Configuration list.

This way it's simpler to create a runnable jar especially if you want to do it repeatedly.

Comatulid answered 30/5, 2013 at 6:24 Comment(0)
A
0

Well, got the same Problem and solved it by selecting my GUI to export and not the whole Project.

Andalusia answered 18/1, 2017 at 10:55 Comment(0)
K
0

I had this problem with Eclipse version 2019-03 (4.11.0) and compiler JaveSE-11. Choosing the right launch configuration and exporting runnable jar failed over and over again with an error

Could not find main method from given launch configuration

I've tried to restart Eclipse and do a clean build, but it didn't help.

In the end, I found a workaround to go into the generated jar file (I've used 7zip) and change META-INF/MANIFEST.MF file. The file should have something like this inside:

Manifest-Version: 1.0
Class-Path: .
Main-Class: <package name>.<class name>

Hope it helps someone.

Kealey answered 11/8, 2020 at 14:48 Comment(0)
S
0

I faced the same issue and in my case I found that "launch configuration" was incorrect in Runnable Jar file specification dialog. Somehow, eclipse was automatically taking it. The "Launch configuration" should be java file which has main method. Basically, it is filename-package. The moment I changed my "launch configuration", I was able to create Jar file without any error.

Silence answered 20/7, 2021 at 13:30 Comment(0)
H
0

I had the same issue. To overcome this issue, you need to close all opened files and open a single java class file that has the main() method. Then export it from eclipse and works fine.

Handwriting answered 3/9, 2021 at 7:31 Comment(0)
F
0

I had the same issue, on Java with Eclipse. After some wrong tests, I had a corrupted version of « .classpath » file. I restored an old version of « .classpath » file in root directory and that works !

Faultfinder answered 12/7, 2023 at 13:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.