18.3. IDEs

18.3.1. Eclipse

18.3.1.1. Code Formatting

Under the dev-support/ folder, you will find hbase_eclipse_formatter.xml. We encourage you to have this formatter in place in eclipse when editing HBase code.

Procedure 18.1. Load the HBase Formatter Into Eclipse

  1. Open the EclipsePreferences menu item.

  2. In Preferences, click the JavaCode StyleFormatter menu item.

  3. Click Import and browse to the location of the hbase_eclipse_formatter.xml file, which is in the dev-support/ directory. Click Apply.

  4. Still in Preferences, click Java EditorSave Actions. Be sure the following options are selected:

    • Perform the selected actions on save

    • Format source code

    • Format edited lines

    Click Apply. Close all dialog boxes and return to the main window.

In addition to the automatic formatting, make sure you follow the style guidelines explained in Section 18.10.2.2, “Code Formatting Conventions”

Also, no @author tags - that's a rule. Quality Javadoc comments are appreciated. And include the Apache license.

18.3.1.2. Eclipse Git Plugin

If you cloned the project via git, download and install the Git plugin (EGit). Attach to your local git repo (via the Git Repositories window) and you'll be able to see file revision history, generate patches, etc.

18.3.1.3. HBase Project Setup in Eclipse using m2eclipse

The easiest way is to use the m2eclipse plugin for Eclipse. Eclipse Indigo or newer includes m2eclipse, or you can download it from http://www.eclipse.org/m2e//. It provides Maven integration for Eclipse, and even lets you use the direct Maven commands from within Eclipse to compile and test your project.

To import the project, click FileImportMavenExisting Maven Projects and select the HBase root directory. m2eclipse locates all the hbase modules for you.

If you install m2eclipse and import HBase in your workspace, do the following to fix your eclipse Build Path.

  1. Remove target folder

  2. Add target/generated-jamon and target/generated-sources/java folders.

  3. Remove from your Build Path the exclusions on the src/main/resources and src/test/resources to avoid error message in the console, such as the following:

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

    This will also reduce the eclipse build cycles and make your life easier when developing.

18.3.1.4. HBase Project Setup in Eclipse Using the Command Line

Instead of using m2eclipse, you can generate the Eclipse files from the command line.

  1. First, run the following command, which builds HBase. You only need to do this once.

    mvn clean install -DskipTests
  2. Close Eclipse, and execute the following command from the terminal, in your local HBase project directory, to generate new .project and .classpath files.

    mvn eclipse:eclipse
  3. Reopen Eclipse and import the .project file in the HBase directory to a workspace.

18.3.1.5. Maven Classpath Variable

The $M2_REPO classpath variable needs to be set up for the project. This needs to be set to your local Maven repository, which is usually ~/.m2/repository

If this classpath variable is not configured, you will see compile errors in Eclipse like this:

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:
                

18.3.1.6. Eclipse Known Issues

Eclipse will currently complain about Bytes.java. It is not possible to turn these errors off.

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
             

18.3.1.7. Eclipse - More Information

For additional information on setting up Eclipse for HBase development on Windows, see Michael Morello's blog on the topic.

18.3.2. IntelliJ IDEA

You can set up IntelliJ IDEA for similar functinoality as Eclipse. Follow these steps.

Project Setup in IntelliJ IDEA

  1. Select Import ProjectImport Project From External ModelMaven

  2. You do not need to select a profile. Be sure Maven project required is selected, and click Next.

  3. Select the location for the JDK.

Using the HBase Formatter in IntelliJ IDEA. Using the Eclipse Code Formatter plugin for IntelliJ IDEA, you can import the HBase code formatter described in Section 18.3.1.1, “Code Formatting”.

18.3.3. Other IDEs

It would be userful to mirror the Section 18.3.1, “Eclipse” set-up instructions for other IDEs. If you would like to assist, please have a look at HBASE-11704.

comments powered by Disqus