如何在非 GUI 服务器环境中运行 libGDX 应用程序?

2022-01-12 00:00:00 server ubuntu linux java libgdx

我构建了一个在我的 PC 桌面上运行良好的 libGDX 应用程序,但是当我尝试在我的 Ubuntu 服务器上运行它时,它会引发以下错误:

I built a libGDX application that runs well on my PC desktop but when I try to run it on my Ubuntu server, it raises the following error:

"LwjglApplication: 无法初始化音频,禁用音频java.lang.UnsatisfiedLinkError:/tmp/libgdxroot/31ce78a2/liblwjgl64.so:/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/../lib/amd64/libjawt.so:符号awt_Unlock,版本 SUNWprivate_1.1 未在文件 libmawt.so 中定义链接时间参考".

"LwjglApplication: Couldn't initialize audio, disabling audio java.lang.UnsatisfiedLinkError: /tmp/libgdxroot/31ce78a2/liblwjgl64.so: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/../lib/amd64/libjawt.so: symbol awt_Unlock, version SUNWprivate_1.1 not defined in file libmawt.so with link time reference".

我知道这是因为我的服务器在非 GUI 模式下运行.但是我怎样才能在这个环境中运行我的 libGDX 应用程序呢?我听说过libGDX 无头后端".但我不知道如何使用它.提前致谢.

I know this is because my server is running in non-GUI mode. But how can I run my libGDX app in this environment?. I've heard about "libGDX headless backend". But I don't know how to use it. Thanks in advance.

推荐答案

我已经为任何正在寻找这个问题的人回答了这个问题.首先,在 build.gradle 文件中添加这两个库:

I've answer my self this question for anyone who's looking for this. First, added these two libraries in the build.gradle file:

compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
compile "org.mockito:mockito-all:1.9.5"

然后,我启动了我的 libGDX,如下所示:

Then, I've started my libGDX as following:

HeadlessNativesLoader.load();
MockGraphics mockGraphics = new MockGraphics();
Gdx.graphics = mockGraphics;
HeadlessNet headlessNet = new HeadlessNet();
Gdx.net = headlessNet;
HeadlessFiles headlessFiles = new HeadlessFiles();
Gdx.files = headlessFiles;
Gdx.gl = mock(GL20.class);
HeadlessApplicationConfiguration config = new HeadlessApplicationConfiguration();
ApplicationListener myGdxGame = EntryPoint.getHeadlessMyGdxGame(config);

和 EntryPoint.getHeadlessMyGdxGame 返回 HeadlessApplication 的继承

and EntryPoint.getHeadlessMyGdxGame return an inherited of HeadlessApplication

相关文章