将 libgdx 项目导入 Eclipse 时未绑定类路径变量 junit 和 log4j

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13734832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:33:39  来源:igfitidea点击:

Unbound classpath variable junit and log4j when importing a libgdx project in to eclipse

javaeclipselibgdxscene2d

提问by user1170304

I'm trying to import and run the project listed here:

我正在尝试导入并运行此处列出的项目:

Scene2d Actions and Event Handling

Scene2d 动作和事件处理

I start by downloading the zip file and then importing it in to eclipse. From here I get the following three errors (after resolving others pertaining to incorrect android version):

我首先下载 zip 文件,然后将其导入 eclipse。从这里我得到以下三个错误(在解决了与不正确的 android 版本有关的其他错误之后):

Description Resource    Path    Location    Type
Unbound classpath variable: 'M2_REPO/junit/junit/4.5/junit-4.5.jar' in project 'game-test-desktop'  game-test-desktop       Build path  Build Path Problem


Description Resource    Path    Location    Type
Unbound classpath variable: 'M2_REPO/junit/junit/4.5/junit-4.5.jar' in project 'netthreads-libgdx'  netthreads-libgdx       Build path  Build Path Problem


Description Resource    Path    Location    Type
Unbound classpath variable: 'M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16.jar' in project 'netthreads-libgdx'    netthreads-libgdx       Build path  Build Path Problem

Does anyone know how to resolve the problem? I have noticed that this junit should be included in the JDT for eclipse but I have installed that with no change in the error. Thanks.

有谁知道如何解决问题?我注意到这个 junit 应该包含在 eclipse 的 JDT 中,但我已经安装了它,错误没有改变。谢谢。

回答by Drew

The problem is that the project has dependencies on libraries which are managed with Maven, which Eclipse isn't automatically setup to handle.

问题是该项目依赖于用Maven管理的库,Eclipse 不会自动设置来处理这些库。

You'll need to first downloadand then install Maven. Then you can open a command-line window and run mvn installfrom your project directory, which will build the code and pull down any required dependencies.

您需要先下载然后安装 Maven。然后您可以打开一个命令行窗口并mvn install从您的项目目录运行,这将构建代码并拉下任何所需的依赖项。

Lastly, you'll need to go into Eclipse and set it up to that it's aware of your local Maven repository...

最后,您需要进入 Eclipse 并将其设置为知道您的本地 Maven 存储库...

  1. Window -> Preferences
  2. Java -> Build Path -> Classpath Variables -> New
  3. namewill be M2_REPO
  4. pathwill be something like c:\users\drew\.m2\repository
  5. Click the OK button twice
  1. 窗口 -> 首选项
  2. Java -> 构建路径 -> 类路径变量 -> 新建
  3. name将会 M2_REPO
  4. path会像 c:\users\drew\.m2\repository
  5. 单击确定按钮两次

If you do a recompile in Eclipse, those errors should go away.

如果您在 Eclipse 中重新编译,这些错误应该会消失。

回答by Blenda Guedes

I agree with Drew, but also restart your eclipse after.

我同意 Drew 的观点,但之后也要重新启动您的 Eclipse。