166.1。日食

166.1.1。代码格式

在 dev-support / 文件夹下,您将找到 _hbase_eclipse formatter.xml 。我们鼓励您在编辑 HBase 代码时在 eclipse 中使用此格式化程序。

转到Preferences→Java→Code Style→Formatter→Import加载 xml 文件。转到Preferences→Java→Editor→Save Actions,确保选中“格式化源代码”和“格式化编辑行”。

除自动格式化外,请确保遵循 common.patch.feedback 中说明的样式指南。

166.1.2。 Eclipse Git 插件

如果您通过 git 克隆项目,请下载并安装 Git 插件(EGit)。附加到您当地的 git 仓库(通过 Git Repositories 窗口),您将能够看到文件修订历史记录,生成补丁等。

166.1.3。使用m2eclipse在 Eclipse 中进行 HBase 项目设置

最简单的方法是使用 Eclipse 的 m2eclipse 插件。 Eclipse Indigo 或更新版本包括 m2eclipse,或者您可以从 http://www.eclipse.org/m2e/ 下载它。它为 Eclipse 提供了 Maven 集成,甚至允许您使用 Eclipse 中的直接 Maven 命令来编译和测试您的项目。

要导入项目,请单击并选择 HBase 根目录。 m2eclipse为您找到所有 hbase 模块。

如果在工作区中安装 m2eclipse 并导入 HBase,请执行以下操作来修复 eclipse Build Path。

  1. 删除 _ 目标 _ 文件夹

  2. 添加 target / generated-jamon 和 target / generated-sources / java 文件夹。

  3. 从构建路径中删除 src / main / resources 和 src / test / resources 上的排除项,以避免在控制台中出现错误消息,如下所示:

    Failed to execute goal
    org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default) on project hbase:
    'An Ant BuildException has occurred: Replace: source file .../target/classes/hbase-default.xml
    doesn't exist 
    

    这也将减少日食构建周期,并使您在开发时更轻松。

166.1.4。使用命令行在 Eclipse 中进行 HBase 项目设置

您可以从命令行生成 Eclipse 文件,而不是使用m2eclipse。

  1. 首先,运行以下命令,构建 HBase。你只需要这样做一次。

    mvn clean install -DskipTests 
    
  2. 关闭 Eclipse,并在终端的本地 HBase 项目目录中执行以下命令,以生成新的 .project 和 .classpath 文件。

    mvn eclipse:eclipse 
    
  3. 重新打开 Eclipse 并将 HBase 目录中的 .project 文件导入工作区。

166.1.5。 Maven 类路径变量

需要为项目设置$M2_REPO类路径变量。这需要设置为您的本地 Maven 存储库,通常是 〜/ .m2 / repository

如果未配置此类路径变量,您将在 Eclipse 中看到如下编译错误:

Description    Resource    Path    Location    Type
The project cannot be built until build path errors are resolved    hbase        Unknown    Java Problem
Unbound classpath variable: 'M2_REPO/asm/asm/3.1/asm-3.1.jar' in project 'hbase'    hbase        Build path    Build Path Problem
Unbound classpath variable: 'M2_REPO/com/google/guava/guava/r09/guava-r09.jar' in project 'hbase'    hbase        Build path    Build Path Problem
Unbound classpath variable: 'M2_REPO/com/google/protobuf/protobuf-java/2.3.0/protobuf-java-2.3.0.jar' in project 'hbase'    hbase        Build path    Build Path Problem Unbound classpath variable: 

166.1.6。 Eclipse 已知问题

Eclipse 目前会抱怨 Bytes.java 。无法关闭这些错误。

Description    Resource    Path    Location    Type
Access restriction: The method arrayBaseOffset(Class) from the type Unsafe is not accessible due to restriction on required library /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar    Bytes.java    /hbase/src/main/java/org/apache/hadoop/hbase/util    line 1061    Java Problem
Access restriction: The method arrayIndexScale(Class) from the type Unsafe is not accessible due to restriction on required library /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar    Bytes.java    /hbase/src/main/java/org/apache/hadoop/hbase/util    line 1064    Java Problem
Access restriction: The method getLong(Object, long) from the type Unsafe is not accessible due to restriction on required library /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar    Bytes.java    /hbase/src/main/java/org/apache/hadoop/hbase/util    line 1111    Java Problem 

166.1.7。 Eclipse - 更多信息

有关在 Windows 上设置 Eclipse for HBase 开发的其他信息,请参阅 Michael Morello 关于该主题的博客。

166.2。 IntelliJ IDEA

您可以设置 IntelliJ IDEA 以实现与 Eclipse 类似的功能。跟着这些步骤。

  1. 选择

  2. 您无需选择配置文件。确保选中所需的 Maven 项目,然后单击 Next 。

  3. 选择 JDK 的位置。

在 IntelliJ IDEA 中使用 HBase Formatter

使用 IntelliJ IDEA 的 Eclipse Code Formatter 插件,您可以导入 eclipse.code.formatting 中描述的 HBase 代码格式化程序。

166.3。其他 IDE

为其他 IDE 镜像 eclipse 设置指令会很有用。如果您想提供帮助,请查看 HBASE-11704 。