简体   繁体   English

如何从GitHub导入源到Eclipse项目

[英]How to import source from GitHub into an Eclipse project

I am trying to use this tool from Google: https://github.com/pcj/google-options 我正在尝试从Google使用此工具: https : //github.com/pcj/google-options

In the example given by Google, they use: 在Google提供的示例中,他们使用:

import com.google.devtools.common.options.OptionsParser;

to allow their example code to use the command line parser. 允许他们的示例代码使用命令行解析器。

When I do this, Eclipse says the referenced files don't exist. 当我这样做时,Eclipse表示引用的文件不存在。

I have tried putting the source file from google-options in a package in my project; 我试图将来自google-options的源文件放在我项目的一个包中; no luck. 没运气。 I tried running Google's example, and it won't even compile. 我尝试运行Google的示例,但它甚至无法编译。 It can't find all of the classes in its own src folder. 它无法在其自己的src文件夹中找到所有类。

Based on my research, I think there's either an issue with a .jar file needing to be in the build path, something to do with Apache Ant, or an issue with GitHub I don't understand. 根据我的研究,我认为可能是在构建路径中需要存在.jar文件问题,与Apache Ant有关,或者与我不了解的GitHub有关。

I'm very new to GitHub; 我是GitHub的新手。 this is the first time I've tried to do anything like this. 这是我第一次尝试做这样的事情。

You should first import this project from GitHub to your local machine. 您应该首先将此项目从GitHub导入到本地计算机。 import statement in your class means that classes from other packages should be imported to this class you're working on. import语句意味着应该将其他包中的类导入到您正在使用的类中。 Import not from the remote source, but from local. 不是从远程源导入,而是从本地导入。

I figured it out. 我想到了。 It needs the guava.jar file found here added to the buildpath. 它需要guava.jar找到的文件在这里加入到构建路径。 After that, it has a couple weird dependency issues with javax, but I just removed those (it was Nullable and Immutable, if anyone's interested). 之后,它与javax存在一些奇怪的依赖关系问题,但我只是删除了这些问题(如果有人感兴趣,它是Nullable和Immutable)。

First you must clone the project and compile it, to do that put the following commands: 首先,您必须克隆项目并进行编译,然后执行以下命令:

  1. Open your terminal and go to the workspace folder: cd {workspace} 打开终端并转到工作空间文件夹: cd {workspace}
  2. Clone the project: git clone https://github.com/pcj/google-options.git 克隆项目: git clone https://github.com/pcj/google-options.git
  3. Compile the project: mvn clean install 编译项目: mvn clean install
    • Check the result, this should print: BUILD SUCCESS 检查结果,这应该打印: BUILD SUCCESS
    • In that step, maven will download all dependencies that the project needs. 在这一步中,maven将下载项目所需的所有依赖项。
  4. To import the project: Launch eclipse, click on File /Import... choose Existing Maven project , browse your workspace where the projetc was cloned. 导入项目:启动eclipse,单击File /Import...选择Existing Maven project ,浏览克隆了projetc的工作区。
  5. Create a class that extends OptionsBase and defines your @Option(s). 创建一个扩展OptionsBase的类并定义您的@Option。 For more information about how to use, see https://github.com/pcj/google-options#usage 有关如何使用的更多信息,请参见https://github.com/pcj/google-options#usage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM