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

How can I run a libGDX application on a non-GUI server environment?(如何在非 GUI 服务器环境中运行 libGDX 应用程序?)

本文介绍了如何在非 GUI 服务器环境中运行 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

这篇关于如何在非 GUI 服务器环境中运行 libGDX 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在非 GUI 服务器环境中运行 libGDX 应用程序

基础教程推荐