Cannot export default Java libGDX project as a jar from Eclipse

梦想的初衷 提交于 2019-12-24 17:04:40

问题


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


回答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.



来源:https://stackoverflow.com/questions/36972509/cannot-export-default-java-libgdx-project-as-a-jar-from-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!