简体   繁体   English

为什么会收到此异常java.lang.NoClassDefFoundError?

[英]Why do I get this exception java.lang.NoClassDefFoundError?

I am trying to use HBase and Hadoop together. 我正在尝试同时使用HBase和Hadoop。 When I run the JAR file I get this error. 当我运行JAR文件时,出现此错误。 Here is my source code: 这是我的源代码:

public class TwitterTable {

    final static Charset ENCODING = StandardCharsets.UTF_8;
    final static String FILE_NAME = "/home/hduser/project04/sample.txt";

    static class Mapper1 extends TableMapper<ImmutableBytesWritable, IntWritable> 
    {
        byte[] value;

        @Override
        public void map(ImmutableBytesWritable row, Result values, Context context) throws IOException 
        {
            value = values.getValue(Bytes.toBytes("text"), Bytes.toBytes(""));
            String valueStr = Bytes.toString(value);
            System.out.println("GET: " + valueStr);
        }
    }

    public static class Reducer1 extends TableReducer<ImmutableBytesWritable, IntWritable, ImmutableBytesWritable> {

        public void reduce(ImmutableBytesWritable key, Iterable<IntWritable> values, Context context)
                throws IOException, InterruptedException {

        }
    }

    public static void main( String args[] ) throws IOException, ClassNotFoundException, InterruptedException 
    {
        Configuration conf = new Configuration();

         @SuppressWarnings("deprecation")
        Job job = new Job(conf, "TwitterTable");
        job.setJarByClass(TwitterTable.class);

        HTableDescriptor ht = new HTableDescriptor( "twitter" );
        ht.addFamily( new HColumnDescriptor("text"));
        HBaseAdmin hba = new HBaseAdmin( conf );

        if(!hba.tableExists("twitter"))
        {
            hba.createTable( ht );
            System.out.println( "Table Created!" );
        }

        //Read the file and add to the database
        TwitterTable getText = new TwitterTable();



        Scan scan = new Scan();
        String columns = "text"; 
        scan.addColumn(Bytes.toBytes(columns), Bytes.toBytes(""));


        TableMapReduceUtil.initTableMapperJob("twitter", scan, Mapper1.class, ImmutableBytesWritable.class,
                IntWritable.class, job);

        job.waitForCompletion(true);


        //getText.readTextFile(FILE_NAME);
    }

    void readTextFile(String aFileName) throws IOException 
     {
            Path path = Paths.get(aFileName);
            try (BufferedReader reader = Files.newBufferedReader(path, ENCODING)){
              String line = null;
              while ((line = reader.readLine()) != null) {
                //process each line in some way
                  addToTable(line);
              }      
            }
          System.out.println("all done!");

     }

    void addToTable(String line) throws IOException
    {
        Configuration conf = new Configuration();
        HTable table = new HTable(conf, "twitter");

        String LineText[] = line.split(","); 

        String row = "";
        String text = "";

        row = LineText[0].toString();
        row = row.replace("\"", "");
        text = LineText[1].toString();
        text = text.replace("\"", "");

        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes("text"), Bytes.toBytes(""), Bytes.toBytes(text));
        table.put(put);
        table.flushCommits();
        table.close();   
    }   
}

I added the class path to the hadoop-env.sh still no luck.. I don't know what's the problem. 我将类路径添加到hadoop-env.sh仍然没有运气..我不知道这是什么问题。 Here my hadoop-env.sh class path : 这是我的hadoop-env.sh类路径:

export HADOOP_CLASSPATH=
    /usr/lib/hbase/hbase-1.0.0/lib/hbase-common-1.0.0.jar:
    /usr/lib/hbase/hbase-1.0.0/lib/hbase-client.jar:
    /usr/lib/hbase/hbase-1.0.0/lib/log4j-1.2.17.jar:
    /usr/lib/hbase/hbase-1.0.0/lib/hbase-it-1.0.0.jar:
    /usr/lib/hbase/hbase-1.0.0/lib/hbase-common-1.0.0-tests.jar:
    /usr/lib/hbase/hbase-1.0.0/conf:
    /usr/lib/hbase/hbase-1.0.0/lib/zookeeper-3.4.6.jar:
    /usr/lib/hbase/hbase-1.0.0/lib/protobuf-java-2.5.0.jar:
    /usr/lib/hbase/hbase-1.0.0/lib/guava-12.0.1.jar

Ok I found it.. maybe you cannot add everything to the class path. 好的,我找到了..也许您不能将所有内容添加到类路径中。 In that case copy all the libraries from the HBase and add into the Hadoop(refer the hadoop.env.sh) 在这种情况下,请从HBase复制所有库,然后将其添加到Hadoop(请参阅hadoop.env.sh)。

HADOOP_DIR/contrib/capacity-scheduler HADOOP_DIR / contrib / capacity-scheduler

It worked for me. 它为我工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么会出现“线程“main”中的异常 java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException”错误? - Why do I get "Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException" error? 我在 android (java.lang.NoClassDefFoundError) 上使用 java 时遇到异常,为什么? - I get an exception using java on android (java.lang.NoClassDefFoundError), why? Android我得到Java.lang.NoClassDefFoundError - Android I get Java.lang.NoClassDefFoundError 我收到一个错误:java.lang.NoClassDefFoundError - I get a error: java.lang.NoClassDefFoundError 异常-java.lang.NoClassDefFoundError - Exception - java.lang.NoClassDefFoundError 为什么线程“main”中出现异常 java.lang.NoClassDefFoundError:? - Why Exception in thread “main” java.lang.NoClassDefFoundError:? 当我在ScalaIDE中运行代码时,为什么会出现`java.lang.NoClassDefFoundError:scala / Function1`? - Why do I get `java.lang.NoClassDefFoundError: scala/Function1` when I run my code in ScalaIDE? 为什么在Java中会收到NoClassDefFoundError异常? - Why do I get a NoClassDefFoundError Exception in Java? 我阅读了 XML 文档 (JDOM),在另一台 PC 上运行它时出现异常 java.lang.NoClassDefFoundError - I read XML documents (JDOM), and I get an exception java.lang.NoClassDefFoundError when running it on another PC 为什么我在线程“ AWT-EventQueue-2” java.lang.NoClassDefFoundError中得到异常? - why i am getting Exception in thread “AWT-EventQueue-2” java.lang.NoClassDefFoundError?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM