SpringBoot运行MapReduce程序打包插件导致类找不到问题

程序结构

在这里插入图片描述
说明:一个非常普通的springboot结构

pom文件打包插件使用

<build>
<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <fork>true</fork>
            <mainClass>com.example.springbootintegrationtest.hadoop.mapreduce.WordCountDriver</mainClass>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
</build>

说明:是以mainClass方式,但是不是这个插件

解压查看jar结构

在这里插入图片描述
说明:这是springboot默认打包的结构, 当作普通jar运行,默认去org下面找,而我们的WordCount程序代码在BOOT_INF下面,所以找不到类

报错(map和reduce类找不到)

在这里插入图片描述
说明:使用hadoop jar运行报错找不到类

使用hadoop官方案例里面的打包插件

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.example.springbootintegrationtest.hadoop.mapreduce.WordCountDriver
                        </mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <configuration>
                <findbugsXmlOutput>true</findbugsXmlOutput>
                <xmlOutput>true</xmlOutput>
                <effort>Max</effort>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.rat</groupId>
            <artifactId>apache-rat-plugin</artifactId>
        </plugin>
    </plugins>
</build>

说明: 是org.apache.maven.plugins哦

使用mvn install看看目录结构

在这里插入图片描述
说明:你的wordCount相关类都在com包里面

查看运行结果

在这里插入图片描述
说明:运行mapreduce job成功

总结

找不到问题一定要去官网找,我找了8个小时,最后就是参考下官方例子就好了

猜你喜欢

转载自blog.csdn.net/weixin_38312719/article/details/115060411