Seqreader is a class that I define to read the Sequencefile file and print some (key,value) to the console window with the complete code as follows:
1 /**2 * Created with IntelliJ idea.3 * User:hadoop4 * date:16-3-145 * Time: Morning 9:576 * To change this template use File | Settings | File Templates.7 */8 Importorg.apache.hadoop.conf.Configuration;9 ImportOrg.apache.hadoop.fs.FileSystem;Ten ImportOrg.apache.hadoop.fs.Path; One ImportOrg.apache.hadoop.io.SequenceFile; A Importorg.apache.hadoop.io.Writable; - Importorg.apache.hadoop.io.IntWritable; - Importorg.apache.hadoop.io.DoubleWritable; the Importorg.apache.hadoop.io.ArrayWritable; - Importorg.apache.hadoop.util.ReflectionUtils; - - Importjava.io.IOException; + ImportJava.net.URI; - + Public classSeqreader { A Public Static voidMain (string[] args)throwsIOException { atString uri=args[0]; - //String uri= "/home/hadoop/2016test/seqtest/10intarray"; -Configuration conf=NewConfiguration (); -FileSystem fs =Filesystem.get (Uri.create (URI), conf); -Path path=NewPath (URI); -Sequencefile.reader reader=NULL; in //doublewritable[] doublewritablearray=new doublewritable[integer.parseint (args[1]); - to /*for (int i=0;i<doublewritablearray.length;++i) { + doublewritablearray[i]=new doublewritable (0.0); - } the */ * Try { $Reader=NewSequencefile.reader (fs,path,conf);Panax NotoginsengIntwritable key =(intwritable) reflectionutils.newinstance (Reader.getkeyclass (), conf); -Doublearraywritable value=(doublearraywritable) reflectionutils.newinstance (Reader.getvalueclass (), conf); the Longposition=reader.getposition (); +String[] Svalue=NULL; A intindex; the intCounter=0; +StringBuilder sb=NewStringBuilder (); - while(Reader.next (Key,value)) { $ if(Key.get ()%integer.parseint (args[1]) ==0){ $System.out.println ("Key:" +key.get ()); -Index=-1; - for(writable Val:value.get ()) { the //Doublewritablearray[++index].set (((doublewritable) val). get ()); - if(counter>10){Wuyi Break; the } -counter++; WuSb.append (((doublewritable) val). Get ()). Append (","); - } AboutSystem.out.println ("Value:" +sb.tostring ()); $ - } - - } A } + finally { the //Ioutils.closestream (reader); - } $ } the the } the classDoublearraywritableextendsarraywritable { the Publicdoublearraywritable () { - Super(doublewritable.class); in } the /* the Public String toString () { About StringBuilder sb=new StringBuilder (); the For (writable Val:get ()) { the doublewritable doublewritable= (doublewritable) Val; the Sb.append (Doublewritable.get ()); + sb.append (","); - } the Sb.deletecharat (Sb.length ()-1);Bayi return sb.tostring (); the } the */ -}
about generating executable jar packages, here are just a few points to note, for more information, refer to: http://www.cnblogs.com/lz3018/p/5228639.html
1) The first is the configuration of the Manifest.mf file, you should ensure that after the configuration is complete, the file has a blank line, use Gedit edit this file, open the "Show line number" function.
The first 4 lines are the valid contents of our configuration, the 5th line is the blank line that our file needs, the 6th line is currently ready to write the character line, at this time we save the file, then our file content is containing the first four lines of characters, plus a blank line, that is, we have a total of 5 lines of files.
2) for Main-class, when the package name is not defined in our class, it is only necessary to write the main class name. (Only the default package name in Eclipse is the class name.)
3) When we use Jar CFM Seqwriter.jar MANIFEST. After the MF *.class has re-punched the jar package, use the command Java-jar Seqwriter.jar part-r-00000 1000 to run the jar package with the hint "noclassdeffounderror":
That is, the class/org/apache/commons/logging/logfactorty is not found, and this class is commons-logging-1.1.1, we just need to add this jar package, how to add, that is, in the MANIFEST.MF file in the Add Class-path property, to configure the path of the jar package to the property ( multiple jar spaces separated), after doing this, use the jar command to regenerate the jar package, then use Java-jar to execute the jar package, and then the following prompt appears:
Still can't find the class, still follow the above method to add the path of the Commons-configuration-1.6.jar to Class-path, and then repackage, run •, as follows:
Similarly, add the Comons.lang-2.4.jar path to the Class-path, and then repackage and run the results as follows:
Run successfully.
Package Seqreader into an executable jar package