Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executable Jar with Eclipse & Libgdx

This is the first time I have tried to create an executable jar file from Eclipse, and I am confused as to how to do so. I know that there is the option to export a java file as a "jar" and "executable jar", but I am not sure how to ensure that my libgdx libraries, assets, and HighScore.txt file are fully integrated and are working. Furthermore, like most packages my package has a myriad of classes - one of which is the main class. How do I export the jar files and instruct eclipse that this specific class is the main class. Here is an image of my file structure:

File Structure in Eclipse

MainSimpleBike is my main class.

like image 416
Sahil Chopra Avatar asked Mar 02 '26 15:03

Sahil Chopra


1 Answers

  1. Using the default jar

    You specify your main class during runtime, like:

    java -jar MyJar.jar MainSimpleBike
    
  2. You may also modify the manifest.txt by following the instruction here:

    http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

    If you modify the manifest.txt, like:

    Main-Class: com.me.mygdxgame.MainSimpleBike
    

    To create a jar:

    jar cfm MyJar.jar Manifest.txt com.me.mygdxgame/*.class
    

    You can simply run:

    java -jar MyJar.jar
    

    Your main class will be picked up automatically.

like image 163
Mingyu Avatar answered Mar 05 '26 06:03

Mingyu