1

When I export the default libgdx project as a runnable JAR file from eclipse and then run the .jar file, it simply pops up a black screen and then closes.

When I run the project code from inside Eclispe, it works fine. The correct red screen with the "bad logic" logo is displayed by the program (this is what is supposed to happen).

If I build the project from the command line using gradle with the command

gradlew desktop:dist

as instructed here

and then run the jar that is created, it will simply open up show a black screen for a second and then close.

The code being used is the default Java libgdx project code:

package com.mygdx.game.tesprac;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class TestLibgdx extends ApplicationAdapter {
SpriteBatch batch;
Texture img;

@Override
public void create () {
    batch = new SpriteBatch();
    img = new Texture("badlogic.jpg");
}

@Override
public void render () {
    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    batch.draw(img, 0, 0);
    batch.end();
}
}

Desktop Launcher:

package com.mygdx.game.tesprac.desktop;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.mygdx.game.tesprac.TestLibgdx;

public class DesktopLauncher {
    public static void main (String[] arg) {
        LwjglApplicationConfiguration config = new     LwjglApplicationConfiguration();
        new LwjglApplication(new TestLibgdx(), config);
    }
}

Additional information

gesse
  • 31
  • 5
  • open `cmd` in location of your .jar and run it by using `java -jar yourJar.jar` command - you will probably observe a stacktrace - paste it here – m.antkowicz May 02 '16 at 13:23
  • Thank you. This has been solved somewhat. The problem was initially that the image file was not even in the jar. Even after building the jar correctly however the image was still unable to be found. The work around for this ended up being simply moving a copy of the image into the same directory as the jar. I still do not know how to get the jar to locate the image without using this trick though. Using Gdx.files.internal(filename) does not work. – gesse May 02 '16 at 19:49

1 Answers1

1

I Finally found the solution and will post it here for others to see.

1.) Ensure the assets folder from the android project is 'linked' in the desktop project. To do this, in Package Explorer drag the assets folder down to the desktop project and when prompted, select the option that allows the folders to be linked.

2.) Right click the desktop project select properties -> build path, then add the android project to the build path under the 'projects' tab.

3.) In the android project right-click the assets folder and select build path -> 'use as source'

4.) Right click the desktop project then select: Export -> Java -> Runnable JAR file, select the 'Package required libraries into generated JAR' option -> Finish.

gesse
  • 31
  • 5