经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » Java相关 » Scala » 查看文章
踩坑 scala 打包上传 找不到类
来源:cnblogs  作者:noor9  时间:2021/1/25 10:46:12  对本文有异议

出现的问题

? 打包后上传到 spark-submit 提交,报错集群找不到class

寻找原因

  1. 创建是object文件,main方法可执行,在此确定代码编写没问题,寻找别的原因

  2. clean 后重新打包,发现无效

  3. 更换打包方法

    • 一开始是使用的maven中的package打包,然后改成了去 Artifacts中打包,上传后依然找不到,自己去jar包中查找找不到对应类,目标指向配置
  4. 去看maven配置,最后在pom.xml找到原因,翻看博客发现相比之前少写了一项配置

    1. <executions>
    2. <execution>
    3. <goals>
    4. <goal>compile</goal>
    5. <goal>testCompile</goal>
    6. </goals>
    7. <configuration>
    8. <args>
    9. <arg>-dependencyfile</arg>
    10. <arg>${project.build.directory}/.scala_dependencies</arg>
    11. </args>
    12. </configuration>
    13. </execution>
    14. </executions>

    PS:这是应该放到 scala-maven-plugin 中的

重新package打包上传,sparl-submit运行成功

关于插件

? 去网上查询插件相关内容:scala-maven-plugin是用来让maven能够编译、测试、运行scala项目的

  1. <goal>compile</goal>编译scala code
  2. <goal>testCompile</goal>编译test code

写在最后 一个完整的pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>cn.itcast</groupId>
  7. <artifactId>spark</artifactId>
  8. <version>0.1.0</version>
  9. <properties>
  10. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  11. <scala.version>2.11.8</scala.version>
  12. <spark.version>2.2.0</spark.version>
  13. <slf4j.version>1.7.16</slf4j.version>
  14. <log4j.version>1.2.17</log4j.version>
  15. </properties>
  16. <dependencies>
  17. <dependency>
  18. <groupId>org.scala-lang</groupId>
  19. <artifactId>scala-library</artifactId>
  20. <version>${scala.version}</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>org.apache.spark</groupId>
  24. <artifactId>spark-core_2.11</artifactId>
  25. <version>${spark.version}</version>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.apache.spark</groupId>
  29. <artifactId>spark-sql_2.11</artifactId>
  30. <version>${spark.version}</version>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.apache.hadoop</groupId>
  34. <artifactId>hadoop-client</artifactId>
  35. <version>2.7.5</version>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.apache.spark</groupId>
  39. <artifactId>spark-hive_2.11</artifactId>
  40. <version>${spark.version}</version>
  41. </dependency>
  42. <dependency>
  43. <groupId>org.slf4j</groupId>
  44. <artifactId>jcl-over-slf4j</artifactId>
  45. <version>${slf4j.version}</version>
  46. </dependency>
  47. <dependency>
  48. <groupId>org.slf4j</groupId>
  49. <artifactId>slf4j-api</artifactId>
  50. <version>${slf4j.version}</version>
  51. </dependency>
  52. <dependency>
  53. <groupId>org.slf4j</groupId>
  54. <artifactId>slf4j-log4j12</artifactId>
  55. <version>${slf4j.version}</version>
  56. </dependency>
  57. <dependency>
  58. <groupId>log4j</groupId>
  59. <artifactId>log4j</artifactId>
  60. <version>${log4j.version}</version>
  61. </dependency>
  62. <dependency>
  63. <groupId>junit</groupId>
  64. <artifactId>junit</artifactId>
  65. <version>4.13.1</version>
  66. <scope>provided</scope>
  67. </dependency>
  68. </dependencies>
  69. <build>
  70. <sourceDirectory>src/main/scala</sourceDirectory>
  71. <testSourceDirectory>src/test/scala</testSourceDirectory>
  72. <plugins>
  73. <plugin>
  74. <groupId>org.apache.maven.plugins</groupId>
  75. <artifactId>maven-compiler-plugin</artifactId>
  76. <version>3.2</version>
  77. <configuration>
  78. <source>1.8</source>
  79. <target>1.8</target>
  80. <encoding>UTF-8</encoding>
  81. </configuration>
  82. </plugin>
  83. <plugin>
  84. <groupId>net.alchim31.maven</groupId>
  85. <artifactId>scala-maven-plugin</artifactId>
  86. <version>3.2.0</version>
  87. <executions>
  88. <execution>
  89. <goals>
  90. <goal>compile</goal>
  91. <goal>testCompile</goal>
  92. </goals>
  93. <configuration>
  94. <args>
  95. <arg>-dependencyfile</arg>
  96. <arg>${project.build.directory}/.scala_dependencies</arg>
  97. </args>
  98. </configuration>
  99. </execution>
  100. </executions>
  101. </plugin>
  102. <plugin>
  103. <groupId>org.apache.maven.plugins</groupId>
  104. <artifactId>maven-shade-plugin</artifactId>
  105. <version>3.1.1</version>
  106. <executions>
  107. <execution>
  108. <phase>package</phase>
  109. <goals>
  110. <goal>shade</goal>
  111. </goals>
  112. <configuration>
  113. <filters>
  114. <filter>
  115. <artifact>*:*</artifact>
  116. <excludes>
  117. <exclude>META-INF/*.SF</exclude>
  118. <exclude>META-INF/*.DSA</exclude>
  119. <exclude>META-INF/*.RSA</exclude>
  120. </excludes>
  121. </filter>
  122. </filters>
  123. <transformers>
  124. <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  125. <mainClass></mainClass>
  126. </transformer>
  127. </transformers>
  128. </configuration>
  129. </execution>
  130. </executions>
  131. </plugin>
  132. </plugins>
  133. </build>
  134. </project>

原文链接:http://www.cnblogs.com/xp-thebest/p/14295887.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号