Eclipse compilation runs the MapReduce program Hadoop

Source: Internet
Author: User
Tags hdfs dfs

Method line, but the code is 2.0 please modify

preparatory work

Install Eclipse and search for installation directly in Ubuntu Software Center.

On the left-hand taskbar, click Ubuntu Software Center.

Ubuntu Software Center

Search for Eclipse in the search bar in the upper-right corner, click Eclipse in the search results, and click Install.

Install Eclipse

This completes the installation of Eclipse. The default installation directory for Eclipse is:/usr/lib/eclipse. Installing Hadoop-eclipse-plugin

Download Hadoop2x-eclipse-plugin, will release in the Hadoop-eclipse-kepler-plugin-2.2.0.jar (although labeled 2.2.0, but under the 2.6.0 is not a problem, should be in the 2.x version Can be copied to the plugin folder in the Eclipse installation directory and run Eclipse-clean to restart Eclipse.

CD ~/download/unzip./hadoop2x-eclipse-plugin-master.zip cd/usr/lib/eclipse sudo cp ~/download/hadoop2x-eclipse-plugin-master/ Release/hadoop-eclipse-kepler-plugin-2.2.0.jar./plugins/./eclipse-clean Configure Hadoop-eclipse-plugin

After you start Eclipse, you can see DFS Locations in Project Explorer on the left (if you see the Welcome interface, click the x close in the upper left corner to see it).

After installing the Hadoop-eclipse-plugin plug-in effect

The plugin requires further configuration.

First step: Select Preference under the Window menu.

Open preference

A form will pop up with the Hadoop map/reduce option on the left side of the form, click this option to select the installation directory for Hadoop (for example,/usr/local/hadoop,ubuntu is not a good choice for the directory, just enter the line).

Select the installation directory for Hadoop

The second step: switch map/reduce working directory, choose the Window menu under Open perspective and other, pop up a form, select the Map/reduce option to switch.

Switch map/reduce working directory

Step three: Establish a connection to the Hadoop cluster, click the Map/reduce Locations panel in the lower right corner of the Eclipse software, right-click in the panel and select New Hadoop location.

Establishing a connection to a Hadoop cluster

In the pop-up General Options panel for Master settings, set the configuration to be consistent with Hadoop, such as the Hadoop pseudo-distributed configuration I used, set Fs.defaultfs to hdfs://localhost:9000, then DFS maste The Post for R should also be changed to 9000.

Location Name is free to fill in, Map/reduce Master Host will fill in your native IP (localhost also line), Port default is 50020. The final settings are as follows:

Settings for Hadoop location

Then switch to the Advanced Parameters Options panel, which has a detailed configuration, remembering that it needs to be consistent with the configuration of Hadoop (configuration files in/usr/local/hadoop/etc/hadoop), as I configured the Hadoop.tmp.dir , you need to make changes.

Settings for Hadoop location

Finally click on Finish,map/reduce location to create it.

The configuration is complete. View the contents of a file in HDFs in Eclipse

Once configured, clicking on the MapReduce location in Project Explorer on the left allows you to view the contents of the file directly in HDFS (as shown in the WordCount output) without having to go through the cumbersome HDFS dfs-ls command. If you are unable to view it, try restarting Eclipse.

Use Eclipse to view file contents in HDFs Tips

After the content changes in HDFS, Eclipse does not synchronize refreshes, you need to right click on the MapReduce location in Project Explorer and select Refresh to see the changed files. Create a MapReduce project in Eclipse

Click the File menu and choose New Project ...:

Create Project

Select Map/reduce Project and click Next.

Create a MapReduce project

Fill out project name as WordCount, and click Finish to create the item.

Fill in the project name

At this point, Project Explorer on the left will be able to see the projects you have just created.

Project Creation Complete

Then right-click on the WordCount project you just created and choose New Class

New class

Two places to fill in: Fill in the Org.apache.hadoop.examples at the package and fill in the WordCount in Name.

Fill in the class information

Once you have created the Class, you will see the Wordcount.java file in src in Project. Copy the following WordCount code into the file.

Package org.apache.hadoop.examples; Import java.io.IOException; Import Java.util.StringTokenizer; Import org.apache.hadoop.conf.Configuration; Import Org.apache.hadoop.fs.Path; Import org.apache.hadoop.io.IntWritable; Import Org.apache.hadoop.io.Text; Import Org.apache
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.