解决问题
spark-submit 提交任务,报包找不到异常。Exception in thread “main” java.lang.NoClassDefFoundError: com/alibaba/fastjson/TypeReference
解决思路
集群环境中没有,集群的worker节点找不到这个包
解决方法
1、提交命令使用 --jars 参数带上包
官方描述:
application-jar: Path to a bundled jar including your application and all dependencies. The URL must be globally visible inside of your cluster, for instance, an hdfs:// path or a file:// path that is present on all nodes. hdfs://localhost:8020
spark-submit
–jars /Users/hezepei/lib/fastjson-1.2.47.jar
–class com.leo.etl.ParseJsonData
–master yarn
/Users/hezepei/workspace/leo-quarter2/target/leo-quarter2-1.0.jar
/data/leo-quarter2/data/mocktest
/data/leo-quarter2/data/out
多个包简写:
spark-submit
–jars $(echo /Users/hezepei/lib/*.jar | tr ’ ’ ‘,’)
–class com.leo.etl.ParseJsonData
–master yarn
/Users/hezepei/workspace/leo-quarter2/target/leo-quarter2-1.0.jar
/data/leo-quarter2/data/mocktest
/data/leo-quarter2/data/out
2、配置文件中设置HDFS中集群的包路径,spark程序跑任务默认去这个路径找。将jar包 put到这个路径。