Syangy 2021-07-27 18:50 采纳率: 100%
浏览 284
已结题

我的jar包在hadoop运行程序出现了问题(非代码错误)

代码放到MyMatrix这个文件夹下的MartrixMultiply.java文件里面。程序的编译和打包成jar包一切顺利,但是当我运行在hadoop下运行jar包时出了问题。我输入了以下linux命令:hadoop jar MartrixMultiply.jar MyMatrix/MartrixMultiply 但是给我报出了如下错误:Exception in thread "main" java.lang.ClassNotFoundException: MyMatrix.MartrixMultiply。我也不太懂java,艘了很多资料没找到解决的办法,请问我是哪里错了

package MyMatrix;
 
import java.io.IOException;
import java.util.Iterator;
 
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
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.MultipleInputs;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
 
public class MartrixMultiply{
    
    /**
     * 最后得到的矩阵的列数
     */
    public static final int COL_COUNT = 2;
    
    /**
     * 最后得到的矩阵的行数
     */
    public static final int ROW_COUNT = 4;
    
    /**
     * A矩阵的列数或者是B矩阵的行数
     */
    public static final int BROW_ACOL= 3;
    
    public static class MartrixMaperA extends Mapper<LongWritable, Text, Text, Text>{
 
        @Override
        protected void map(LongWritable key, Text value, Context context)
                throws IOException, InterruptedException {
            
            String valueStr = value.toString();
            String[] items = valueStr.split(",");
            
            int rowIndex = Integer.parseInt(items[0]);
            int colIndex = Integer.parseInt(items[1]);
            int valueInt = Integer.parseInt(items[2]);
            
            Text outKey = null;
            Text outValue = null;
            for(int i=0;i<COL_COUNT;i++){
                outKey = new Text(rowIndex + "," + (i+1));
                outValue = new Text("a,"+colIndex+","+valueInt);
                context.write(outKey, outValue);
            }
            
        }
        
    }
    
    public static class MartrixMaperB extends Mapper<LongWritable, Text, Text, Text>{
 
        @Override
        protected void map(LongWritable key, Text value, Context context)
                throws IOException, InterruptedException {
            
            String valueStr = value.toString();
            String[] items = valueStr.split(",");
            
            int rowIndex = Integer.parseInt(items[0]);
            int colIndex = Integer.parseInt(items[1]);
            int valueInt = Integer.parseInt(items[2]);
            
            Text outKey = null;
            Text outValue = null;
            for(int i=0;i<ROW_COUNT;i++){
                outKey = new Text((i+1) + "," + colIndex);
                outValue = new Text("b,"+rowIndex+","+valueInt);
                context.write(outKey, outValue);
            }
            
        }
        
    }
    
    public static class MartrixReducer extends Reducer<Text,Text,Text,IntWritable>{
 
        @Override
        protected void reduce(Text key, Iterable<Text> values,Context context)
                throws IOException, InterruptedException {
 
            String[] items = new String[3];
            
            int[] valueA = new int[BROW_ACOL];
            int[] valueB = new int[BROW_ACOL];
            
            Iterator<Text> it = values.iterator();
            while(it.hasNext()){
                items = it.next().toString().split(",");
                if(items[0].equals("a")){
                    valueA[Integer.parseInt(items[1])-1] = Integer.parseInt(items[2]);
                }else if(items[0].equals("b")){
                    valueB[Integer.parseInt(items[1])-1] = Integer.parseInt(items[2]);
                }
            }
            
            int result = 0;
            for(int i=0;i<BROW_ACOL;i++){
                result += valueA[i]*valueB[i];
            }
            context.write(key, new IntWritable(result));
        }
        
    }
    
    @SuppressWarnings("deprecation")
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        
        Path pathA = new Path("hdfs://localhost:9000/Martrix/a.txt");
        Path pathB = new Path("hdfs://localhost:9000/Martrix/b.txt");
        Path pathOut = new Path("hdfs://localhost:9000/Martrix/out");
        
        Configuration conf = new Configuration();
        Job job = new Job(conf,"MartrixMultiply");
        
        job.setJarByClass(MartrixMultiply.class);
        
        MultipleInputs.addInputPath(job, pathA, TextInputFormat.class, MartrixMaperA.class);
        MultipleInputs.addInputPath(job, pathB, TextInputFormat.class, MartrixMaperB.class);
        
        job.setReducerClass(MartrixReducer.class);
        
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);
        
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        
        FileOutputFormat.setOutputPath(job, pathOut);
        
        if(job.waitForCompletion(true)){
            System.exit(0);
        }else{
            System.exit(1);
        }
        
    }
    
}

  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月7日
  • 已采纳回答 7月30日
  • 创建了问题 7月27日

悬赏问题

  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档