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

后端 未结 6 1463
清歌不尽
清歌不尽 2021-01-12 03:42

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 jus

相关标签:
6条回答
  • 2021-01-12 04:07

    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.

    0 讨论(0)
  • 2021-01-12 04:09

    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.

    0 讨论(0)
  • 2021-01-12 04:10

    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 :)
    0 讨论(0)
  • 2021-01-12 04:19

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

    0 讨论(0)
  • 2021-01-12 04:21

    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.

    0 讨论(0)
  • 2021-01-12 04:31

    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.

    0 讨论(0)
提交回复
热议问题