Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli2/Option
今天,在做canopy算法实例时,遇到这个问题,所以记录下来。下面是源码:
package czx.com.mahout; import java.io.IOException; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
import org.apache.hadoop.util.ToolRunner;
import org.apache.mahout.common.AbstractJob;
import org.apache.mahout.math.RandomAccessSparseVector;
import org.apache.mahout.math.VectorWritable; public class TextVecWrite extends AbstractJob { public static void main(String[] args) throws Exception {
ToolRunner.run(new Configuration(), new TextVecWrite(), args);
} /**
* TextVecWriterMapper
* @author czx
*;
*/
public static class TextVecWriterMapper extends Mapper<LongWritable, Text, LongWritable,VectorWritable >{
@SuppressWarnings("unchecked")
@Override
protected void map(LongWritable key, Text value,
@SuppressWarnings("rawtypes") org.apache.hadoop.mapreduce.Mapper.Context context)
throws IOException, InterruptedException {
String[] split = value.toString().split("\\s{1,}");
RandomAccessSparseVector vector = new RandomAccessSparseVector(split.length);
for(int i=0;i<split.length;++i){
vector.set(i, Double.parseDouble(split[i]));
}
VectorWritable vectorWritable = new VectorWritable(vector);
context.write(key, vectorWritable);
}
} /**
* TextVectorWritableReducer
* @author czx
*
*/
public static class TextVectorWritableReducer extends Reducer<LongWritable, VectorWritable, LongWritable , VectorWritable >{
@Override
protected void reduce(LongWritable arg0, Iterable<VectorWritable> arg1,
Context arg2)
throws IOException, InterruptedException {
for(VectorWritable v:arg1){
arg2.write(arg0, v);
}
}
} @Override
public int run(String[] arg0) throws Exception {
addInputOption();
addOutputOption();
if(parseArguments(arg0)==null){
return -1;
}
Path input = getInputPath();
Path output = getOutputPath();
Configuration conf = getConf(); Job job = new Job(conf,"textvectorWritable with input:"+input.getName());
job.setOutputFormatClass(SequenceFileOutputFormat.class);
job.setMapperClass(TextVecWriterMapper.class);
job.setReducerClass(TextVectorWritableReducer.class);
job.setMapOutputKeyClass(LongWritable.class);
job.setOutputValueClass(VectorWritable.class);
job.setOutputKeyClass(LongWritable.class);
job.setOutputValueClass(VectorWritable.class);
job.setJarByClass(TextVecWrite.class); FileInputFormat.addInputPath(job, input);
SequenceFileOutputFormat.setOutputPath(job, output); if(!job.waitForCompletion(true)){
throw new InterruptedException("Canopy Job failed processing "+input);
}
return 0;
}
}
将程序编译打包成JAR并运行如下:
hadoop jar ClusteringUtils.jar czx.com.mahout.TextVecWrite -i /user/hadoop/testdata/synthetic_control.data -o /home/czx/1
但出现如下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli2/Option
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.apache.hadoop.util.RunJar.main(RunJar.java:205)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli2.Option
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
最后,发现是将mahout根目录下的相应的jar包复制到hadoop-2.4.1/share/hadoop/common/lib文件夹下时,少复制了mahout-core-0.9-job.jar,于是复制mahout-core-0.9-job.jar后,重新启动hadoop即可。
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli2/Option的更多相关文章
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
学习架构探险,从零开始写Java Web框架时,在学习到springAOP时遇到一个异常: "C:\Program Files\Java\jdk1.7.0_40\bin\java" ...
- MyEclipse8.5集成Tomcat7时的启动错误:Exception in thread “main” java.lang.NoClassDefFoundError org/apache/commons/logging/LogFactory
今天,安装Tomcat7.0.21后,单独用D:\apache-tomcat-7.0.21\bin\startup.bat启动web服务正常.但在MyEclipse8.5中集成配置Tomcat7后,在 ...
- MyEclipse8.5集成Tomcat7时的启动错误:Exception in thread “main” java.lang.NoClassDefFoundError org/apache/commons/logging/LogFactory
今天,安装Tomcat7.0.21后,单独用D:\apache-tomcat-7.0.21\bin\startup.bat启动web服务正常.但 在MyEclipse8.5中集成配置Tomcat7后, ...
- 【转】MyEclipse8.5集成Tomcat7时的启动错误:Exception in thread “main” java.lang.NoClassDefFoundError org/apache/commons/logging/LogFactory
http://www.cnblogs.com/newsouls/p/4021198.html 今天,安装Tomcat7.0.21后,单独用D:\apache-tomcat-7.0.21\bin\sta ...
- shiro报错SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".和Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
未能加载类"org.slf4j.impl.StaticLoggerBinder" 解决方案: <dependency> <groupId>org.slf4j ...
- spark-shell报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStream
环境: openSUSE42.2 hadoop2.6.0-cdh5.10.0 spark1.6.0-cdh5.10.0 按照网上的spark安装教程安装完之后,启动spark-shell,出现如下报错 ...
- 报错:Exception in thread "main" java.lang.NoClassDefFoundError: Lorg/apache/hadoop/fs/FileSystem
报错现象: Exception in thread "main" java.lang.NoClassDefFoundError: Lorg/apache/hadoop/fs/Fil ...
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/CanUnbuffer
在执行spark on hive 的时候在 sql.show()处报错 : Exception in thread "main" java.lang.NoClassDefFoun ...
- Exception in thread main java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFacto
报错: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/juli/logging/Log ...
随机推荐
- DOM例子小结(一)
一.点击按钮切换图片 核心思路: 1.首先获取元素 2.为元素添加点击事件 3.当事件被触发时运行代码 <!DOCTYPE html> <html lang="en&quo ...
- new 做了什么
var a=function(){ this.che1 = function () { console.log(1) } this.che2 = function () { console.log(2 ...
- 上传200G文件
最近遇见一个需要上传百G大文件的需求,调研了七牛和腾讯云的切片分段上传功能,因此在此整理前端大文件上传相关功能的实现. 在某些业务中,大文件上传是一个比较重要的交互场景,如上传入库比较大的Excel表 ...
- golang rabbitmq实践 (一 rabbitmq配置)
1:环境选择 系统为ubuntu 15.04 ,我装在虚拟机里面的 2:rabbitmq tabbitmq 3.5.4 download url : http://www.rabbitmq.com/ ...
- 关于项目中的一些经验:封装activity、service的基类,封装数据对象
经验一,将几个页面公用的数据,和方法进行封装,形成一个baseActivity的类: package com.ctbri.weather.control; import java.util.Array ...
- final修饰的类,其属性和方法默认是被final修饰的吗?
在论坛上,看到一个问题,当然,各位聪明的客官想必已经知道问题是什么了,嘿嘿,没错就是文章的标题:final修饰的类,其属性和方法默认是被final修饰的吗? 老实说,刚开始看到这个问题的时候,有点懵. ...
- 【SpringBoot-创建项目】一.通过Idea创建SpringBoot项目
一.首先我们通过Idea创建一个新项目 二.选择sdk和快速构建模板 三.填写项目基本信息 三.选择项目依赖 四.填写项目名和本地项目路径 六.完成项目创建,查看项目目录层级 最终:主要是在创建项目的 ...
- shell脚本之结构化命令if...then...fi
if的用法日常主要用于数值或者字符串的比较来实现结构化的,模拟人脑,就是如果遇到什么事情,我们应该做什么 语法格式分为 1. if command;then command;fi (如果if满足 ...
- Word2Vec模型参数 详解
用gensim函数库训练Word2Vec模型有很多配置参数.这里对gensim文档的Word2Vec函数的参数说明进行翻译,以便不时之需. class gensim.models.word2vec.W ...
- Flask基础以及Response三剑客
Flask的特点: 优点:小而精.三方组件全 缺点: 性能相对较差 因为依赖三方组件所以在更新的时候难免不同步 基础模板 from flask import Flask app = Flas ...