尝试使用Maven和Eclipse运行libGDX [英] Trying to run libGDX with Maven and Eclipse

查看:97
本文介绍了尝试使用Maven和Eclipse运行libGDX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许是一个新手问题...

Maybe a newbie question...

我一直在研究LWJGL项目,在这里我使用Maven来管理依赖项.在其中,我想使用libgdx库的某些部分.因此,我认为在将其添加到主项目之前,至少要先运行一个helloworld.

I've been working on a LWJGL project, where I use Maven to manage dependencies. In it, I want to use some parts of the libgdx library. So I figured I will first run at least a helloworld working with it before I add it to my main project.

所以在我的pom.xml中,我有这个:

So in my pom.xml I have this:

        <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-backend-lwjgl -->
        <dependency>
            <groupId>com.badlogicgames.gdx</groupId>
            <artifactId>gdx-backend-lwjgl</artifactId>
            <version>1.9.11</version>
            <scope>test</scope>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-platform -->
        <dependency>
            <groupId>com.badlogicgames.gdx</groupId>
            <artifactId>gdx-platform</artifactId>
            <version>1.9.11</version>
            <scope>test</scope>
        </dependency>
                
        
        <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx -->
        <dependency>
            <groupId>com.badlogicgames.gdx</groupId>
            <artifactId>gdx</artifactId>
            <version>1.9.11</version>
        </dependency>

文件的其他内容与正在运行的项目相同,并且100%处于工作状态.

The other contents of the file are the same as in a working project and are 100% working.

在此之前,我尝试创建一个单独的libgdx项目,但是...没有用.但是,我看到应该运行该程序的代码是:

I tried creating a separate libgdx project before that and... it didn't work. But, I saw that the code that was supposed to run the program was:

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

所以我在我的maven项目中使用了它.当我以Java应用程序身份运行"时,出现以下错误:

So I used that in my maven project. When I do "run as a Java Application", the error is the following:

Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/backends/lwjgl/LwjglApplicationConfiguration
    at org.boby.RayTracing.main.Main.main(Main.java:179)

如果我执行Maven构建,它会告诉我软件包com.badlogic.gdx.backends.lwjgl不存在"

And if I do a Maven Build, it tells me that "package com.badlogic.gdx.backends.lwjgl does not exist"

我在Maven的jar文件中寻找了该软件包,这些jar文件是从"Maven依赖项"下载的.文件夹,我在gdx-backend-lwjgl-1.9.11.jar中找到了它-正确的位置.

I looked for that package in the jars Maven downloaded in the "Maven dependencies" folder and I found it in gdx-backend-lwjgl-1.9.11.jar - right where it should be.

该软件包显然在那里,但是Java找不到它.我该如何解决?

The package is apparently there, but Java cannot find it. How can I fix that?

一些其他信息:Windows 10,日食氧气,Maven 3.6.0,JRE 1.8.0_191,JDK 8

Some additional information: Windows 10, eclipse oxygen, Maven 3.6.0, JRE 1.8.0_191, JDK 8

先谢谢您!我已经为此努力了好几个小时.

Thank you in advance! I've been banging my head on this for hours.

我取得了一些进展.看起来像测试"搞砸了,所以我删除了那些声明.现在我收到以下错误:

I made some progress. Looks like the "test" was messing things up so I removed those statements. Now I get the following Error:

Exception in thread "main" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load shared library 'gdx64.dll' for target: Windows 10, 64-bit
    at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:125)
    at com.badlogic.gdx.utils.GdxNativesLoader.load(GdxNativesLoader.java:33)
    at com.badlogic.gdx.backends.lwjgl.LwjglNativesLoader.load(LwjglNativesLoader.java:47)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:83)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:71)
    at org.boby.RayTracing.main.Main.main(Main.java:178)

似乎我需要在依赖项中包含gdx-natives.jar,但找不到适用于它的Maven存储库.

It looks like I need to include gdx-natives.jar in my dependencies, but I can't find a maven repository for it.

推荐答案

如果您定义gdx-platform dep,您可以让Maven来完成这项工作:

You can let Maven do the work if you define the gdx-platform dep like this:

<dependency>
            <groupId>com.badlogicgames.gdx</groupId>
            <artifactId>gdx-platform</artifactId>
            <version>1.9.11</version>
            <classifier>natives-desktop</classifier>
</dependency>

这将加载包括gdx64.dll在内的本地jar,因此您不必在构建路径中向项目添加任何外部jar.

This will load the natives jar including the gdx64.dll so you don't have to add any external jar to your project in the build path.

一个旁注是:如果您使用标准的Maven repo目录结构,并且使用Gdx.files.internal("fileName")语句加载资产,则需要在主/存储库中定义一个具有相同名称的文件夹作为您将代码放入其中的包.(即main/java/myPackage与/main/repository/myPackage相关).我为此付出了一些努力,因为我通常不必在存储库目录中定义一个包文件夹.

A side note is: if you use the standard Maven repo directory structure and you load assets with the Gdx.files.internal("fileName") statement you need to define a folder in the main/repository with the same name as the package you have your code in. (i.e. main/java/myPackage relates to /main/repository/myPackage). I struggled a bit with this because I don't normaly have to define a package folder int the repository dir.

这篇关于尝试使用Maven和Eclipse运行libGDX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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