无法将默认Java libGDX项目从Eclipse导出为jar [英] Cannot export default Java libGDX project as a jar from Eclipse

查看:119
本文介绍了无法将默认Java libGDX项目从Eclipse导出为jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从eclipse导出默认的libgdx项目作为可运行的JAR文件然后运行.jar文件时,它只会弹出一个黑屏然后关闭。

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.

当我从Eclispe内部运行项目代码时,它工作正常。程序显示带有坏逻辑徽标的正确红色屏幕(这应该发生)。

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).

如果我从命令行构建项目使用带有命令的gradle

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

gradlew desktop:dist

按照此处的说明

然后运行创建的jar,它将打开显示黑屏一秒然后关闭。

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

使用的代码是默认的Java libgdx项目代码:

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();
}
}

桌面启动器:

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);
    }
}

其他信息

推荐答案

我终于找到了解决方案并将其发布在此处供其他人查看。

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

1。)确保android项目中的assets文件夹在桌面项目中是链接的。为此,在Package Explorer中将assets文件夹向下拖动到桌面项目,并在出现提示时选择允许链接文件夹的选项。

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。)右单击桌面项目选择属性 - >构建路径,然后将android项目添加到'projects'选项卡下的构建路径。

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

3。)在android项目右键单击assets文件夹并选择构建路径 - >'use as source'

4。)右键单击桌面项目,然后选择:Export - > Java - > Runnable JAR文件,选择'Package required libraries into generated JAR'选项 - > Finish。

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

这篇关于无法将默认Java libGDX项目从Eclipse导出为jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆