Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added hadoop version to commands since practically everyone is working with hadoop 2+

...

Eclipse is an open source development community. If you have not already done so, download and install Eclipse on your development machine. For more information, see Eclipse and Eclipse IDE for Java Developers.

Download and Install the Eclipse Plugins

For Pig, you need the JavaCC plugin and theSubclipse Subversion plugin.

To download and install the plugins:

  1. Open Eclipse
  2. Select Help > Software Updates... > Available Software
  3. Add the two plugin sites by pressing Add Site... Button
  4. http://eclipse-javacc.sourceforge.netImage Removed
  5. http://subclipse.tigris.org/update_1.4.xImage Removed
  6. Select the plugins that appear under these sites
  7. Press Install - and follow the prompts to download and install the plugins

Add the Pig Trunk Repository

To add the Pig trunk repository:

  1. Open Eclipse
  2. Select file > New > Other...
  3. Choose SVN, Repository Location > Next
  4. Under the General tab:
  5. URL: http://svn.apache.org/repos/asf/pig/trunkImage Removed
  6. Use a custom label: Pig
  7. Click Finish

To view the results:

  • Window > Open Perspective > Other... > SVN Repository Exploring
  • Window > Show View > SVN Repositories

Create a Java Project

Checkout Pig

Create First, create a directory on your development machine (for example "mypig") and checkout the Pig source from SVN: http://svn.apache.org/repos/asf/pig/trunkImage Removed

Note: Windows users need to download and install TortoiseSVN (http://tortoiseSVN.tigris.org/Image Removed)

...

Generate eclipse files:

ant clean eclipse-files -Dhadoopversion=23

Pre-compile and generate sources

ant compile gen -Dhadoopversion=23

Import Pig project into Eclipse

  1. Open Eclipse
  2. Select file > New > Other ...
  3. Select Java Project
  4. On the New Java Project dialog:
  5. Project name: PigProject
  6. Select: Create project from existing source
  7. Directory: browse to the "mypig" directory on your development machine and select the Trunk directory
  8. Click Next
  9. Click Finish

To view the results:

  • Window > Open Perspective > Java
  • Window > Show View > ''see the various options ...''

Update the Build Configuration

  • run 'ant eclipse-files' in trunk/ dir.
  • Refresh the project in eclipse
    You are all set now!

The 'ant eclipse-files' target that generates eclipse configuration does not exist in revisions before r938733. So if you checked out an earlier version, you have to follow the steps below -

After the Java project is created, update the build configuration.

To update the build configuration:

  1. Open Eclipse
  2. Select Window > Open Perspective > Java (to open the !MyPig project)
  3. Select Project > Properties
  4. For the Java Build Path, check the settings as shown below.

Source

Code Block

lib-src/bzip2
lib-src/shock
src -> Make sure nothing is excluded
src-gen -> To get this do "ant clean jar" externally which will create this dir (refresh in eclipse to see it)
shims -> shims/src/hadoopxx
shims-test -> shims/test/hadoopxx
test -> Make sure nothing is excluded

The default output folder should be bin.

Libraries

Code Block

lib/*.jar
build/ivy/lib/Pig/*.jar

NOTE:

  1. For pig sources checked out from Apache before revision r771273, replace "build/ivy/lib/Pig" with "lib". Revision r771273 and above in apache svn use ivy to resolve dependencies need to build pig.
  2. If you are building piggybank you will need few extra jars. You can find all of those in build/ivy/lib/Pig/ once you run jar target of ant successfully.

Order and Export

...

  1. File->Import
  2. Select General->Existing Projects Into Workspace
  3. Select root directory (point to <top-level-directory>)
  4. Click Finish
  5. Project -> Properties -> Java Build Path -> Source -> Add Folder test/perf/pigmix/src/java
  6. Project -> Properties -> Java Build Path -> Libraries -> Remove javacc-4.2.jar.
  7. Project -> Properties -> Java Build Path -> Libraries -> Add JAR test/perf/pigmix/lib/sdsuLibJKD12.jar.
  8. Project -> Properties -> Java Build Path -> Libraries -> Add External JAR hadoop-yarn-server-applicationhistoryservice-*.jar. (I had to find and download this jar myself. It is needed for running tests.)

Run Pig Main

  1. Create a new Run Configurations
  2. Pick "org.apache.pig.Main" as the Main class

Run Pig Unit test

  1. Create a new Junit Run Configurations, pick any Pig test suite as "Test class"
  2. In "VM arguments", put "-Xmx1024m"
  3. Change "Working directory" into your PIG_HOME
  4. In Classpath, add user entries "$PIG_HOME/build/classes" and "$PIG_HOME/pig*.jar"

Troubleshooting

  • Build problems: Check if eclipse is using JDK version 1.6, pig needs it (Under Preferences/Java/Compiler).

Tips

  • To build using eclipse , open the ant window (Windows/Show View/Ant) , then drag and drop build.xml under your project to this window. Double click on jar in that will build pig.jar, on test will run unit testsIf you encounter this error: Missing required library: 'build/ivy/lib/Pig/javacc-4.2.jar' try one of the solutions described in PIG-3399.