Submit a job with Hadoop Eclipse plugin and add multiple third-party jars

Source: Internet
Author: User

From: http://heipark.iteye.com/blog/1171923

Through "Conf.set" ("Tmpjars", jars); "You can set up a third-party jar that has been just adding a jar, running OK, and I'm going to add multiple jars today and find that MapReduce is not found at runtime. Class (ClassNotFoundException), the trace code found that the jar file did upload to HDFs, so there was no solution, and then the jar was uploaded to HDFs, Then using the Distributedcache.addfiletoclasspath () method does not work either. Depressed half-day, later saw Job.xml in a strange setting, Mapred.job.classpath.files value for "/user/heipark/lib/commons-lang-2.3.jar; /user/heipark/lib/guava-r08.jar ", you can see that this delimiter is a semicolon (my OS is Windows), the Linux system and the Hadoop system are generally separated by commas and colons, and then I continue to dig, The Discovery Distributedcache.addarchivetoclasspath () method (Tmpjars also used this method) uses "System.getproperty (" Path.separator "), so the inspiration flashes, Modify this value to be the colon of the Linux system, I am a cha, actually succeeded, engaged me for 4 hours, Eclipse finally can add several third party jar package. Encapsulates the method, adding the jar package directly to the main method.

Call:

Addtmpjar ("D:/java/new_java_workspace/scm/lib/guava-r08.jar", conf);

Method definition:

/**
* Add third-party jar packages for MapReduce
*
* @param jarpath
* Example: D:/java/new_java_workspace/scm/lib/guava-r08.jar
* @param conf
* @throws IOException
*/
public static void Addtmpjar (String jarpath, Configuration conf) throws IOException {
System.setproperty ("Path.separator", ":");
FileSystem fs = filesystem.getlocal (conf);
String Newjarpath = new Path (jarpath). makequalified (FS). ToString ();
String tmpjars = Conf.get ("Tmpjars");
if (Tmpjars = = NULL | | tmpjars.length () = = 0) {
Conf.set ("Tmpjars", Newjarpath);
} else {
Conf.set ("Tmpjars", Tmpjars + "," + Newjarpath);
}
}

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.