两年没搭环境了,最近工作需要,搭建了一次。遇到不少问题,记录于此
- 装jdk
- 装maven
- 装intellij idea社区版
- 先安装git,然后在intellij 中 file -> setting配置git路径
- 安装scala,注意scala安装目录不能有空格。例如“Program Files”中有空格,环境变量会识别不出
wget https://downloads.lightbend.com/scala/2.12.10/scala-2.12.10.tgz
tar -zxvf scala-2.12.10.tgz
cd scala-2.12.10/
#vim /etc/profile
export SCALA_HOME=/home/libs/scala-2.12.10
export PATH=$PATH:$SCALA_HOME/bin
source /etc/profile
- (File => setting )配置Proxy
- (File => setting =>plugins)在intellij plugins 里安装Scala+Plugin+for+IntelliJ+IDEA,然后设置 scala sdk
或者下载scala plugin 安装包
https://plugins.jetbrains.com/plugin/1347-scala/versions
然后 install plugin from disk
设置使用Eclipse风格的快捷键
File --> settings --> keymap --> 在下来框中选中Eclipse
设置字体大小
File --> settings 里面依次找到Editor -> Font选项, size 设置为21,大小就差不多了。
设置sdk
打开java/scala 代码文件,一般会自动 弹出 “setup SDK” 的提示
或者从File中选择Project Structure,设置java sdk
修改 scala SDK 如下图的 “+” 号
安装plugin
File->Setting->plugins->Browse repositories->需要安装的插件的名字->install
####### install from disk
scala plugin
https://plugins.jetbrains.com/plugin/1347-scala/versions
https://blog.youkuaiyun.com/Appleyk/article/details/82180599
MVN
mvn -v,刚开始还没生效,排查了很久。重新开了dos窗口,命令才生效
另外要指定 new project 时 要smaven 版本
为了测试简单,随便输入一个数字做 package 调试不出,结果报 “Detects package statements that do not correspond to the project directory structure and reports classes without package statements”
java的package的名字可以出现数字但是不能是纯数字
安装maven
- 下载安装包
- 设置环境变量,一般是两个 MAVEN_HOME、PATH
- 修改配置文件 .m2/settings.xml
为节省新环境相关jar 的download,也可以从成熟的环境直接scp
~/.m2/repository
IntelliJ IDEA 增加运行内存
-Xmx 增加至2G
然后重启
打开 maven tool window
可以激活相应的profile
一次性刷新所有pom 文件
如出现dependencies 找不到,可 invalidate cache and restart。
常见错误
mvn 编译中断, 导致 有些class 文件 没有编译出来。
重新编译,需要使用 mvn clean
JDK 版本check
更换 Intellij 版本时
删除项目根目录下 .idea/ , 然后用新版本 Intellij 打开。
maven settings.xml
国内环境可以用以下的repo 仓库,以加快速度
<mirrors>
<mirror>
<id>huaweicloud</id>
<name>huawei</name>
<mirrorOf>*</mirrorOf>
<url>https://mirrors.huaweicloud.com/repository/maven/</url>
</mirror>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>alicentral</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
Intellij 创建 hello demo 项目
选中 Maven Archetype 中的 “maven-archetype-quickstart”, 即可快速创建。
maven-archetype-quickstart
新建scala project
注意需要将 Catalog 勾选为 Maven Central, 才能 找到 scala- archetype-simple 模版
resolution
使得 main 目录 unmarked, scala 目录mark 成 source 目录
借助于 Intellij 反编译 Jar
方法一:在 Project Structure 中 “+”
方法二:直接打开 jar 所在的目录
因为直接打开 jar ,intellij 是无法打开的。
但是打开 jar 所在的目录是直接可行的。
两种方法亦可参考这里:
参考链接:https://blog.youkuaiyun.com/qq_26525215/article/details/53239123
FQA
解决方案为:
勾选 profile; 然后删除根目录下的 .idea,然后重新打开 intellij
code insight features are not available
如果 generated-sources 目录的类没有加载进来,很可能是如下原因。自动生成的单个文件太大了。
修改配置解决
idea.max.intellisense.filesize=999999
generated-sources mark (尤其是 Spark 新环境)
not found: value StoreTypes
def serialize(input: AccumulableInfo): StoreTypes.AccumulableInfo = {
- mark 一下 generated source
Generated Sources Root
The IDE considers that files in the Generated Sources root folder are generated automatically rather than written manually, and can be regenerated.
scalac issue
见最后同类章节
Ljava/nio/ByteBuffer
Job aborted due to stage failure: Task serialization failed: java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
此类问题,可从命令行先编译,然后再使用 Intellij
mvn -pl :spark-sql_2.12 -Dtest=none -DwildcardSuites=org.apache.spark.sql.StringFunctionsSuite test
另外一个解决方案:
修改Scala Compile Server中的JDK版本。和本地运行环境版本一致。
亦可参考 https://www.lilinchao.com/archives/2847.html
这里是个陷阱
循环依赖问题
java: Annotation processing is not supported for module cycles. Please ensure that all modules from cycle [spark-catalyst_2.12,spark-sql_2.12] are excluded from annotation processing
这样可以分析循环依赖的点位
借助于 Intellij 反编译 Jar
两种方法:
参考链接:https://blog.youkuaiyun.com/qq_26525215/article/details/53239123
而特殊符号NBSP 则是 c2a0
。因此可以得出NBSP与普通空格视觉上一致,但实际编码是不一样的。
Intellij show history
show local history
spark UT 测试问题
Symbol 'type org.apache.spark.sql.catalyst.plans.PlanTestBase' is missing from the classpath.
This symbol is required by 'trait org.apache.spark.sql.test.SQLTestUtilsBase'.
Make sure that type PlanTestBase is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'SQLTestUtilsBase.class' was compiled against an incompatible version of org.apache.spark.sql.catalyst.plans.
class EMRSQLAuditLogListenerSuite extends SharedSparkSession with JsonTestUtils
加上以下依赖即可
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-catalyst_${scala.binary.version}</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
ISSUES
- scalac: No JDK in module
该类错误在这里进行 设置和调整
注意是 Dependencies 里的 SDK 调整, 并且是针对某个模块进行调整。
以上是最优选择。 或者也可以按照以下步骤,重新编译解决:
mvn clean package -Pyarn -Phadoop-3.2 -Dhadoop.version=3.2.2 -Phive -Phive-thriftserver -DskipTests
然后设置 JDK
然后设置右侧 maven profiles
FQA
- issue
java: OutOfMemoryError: insufficient memory
build process heap size 默认是700,
可以改成 2048
- issue
java: 程序包sun.misc不存在
或报如下错误
cannot access class sun.nio.ch.DirectBuffer (in module java.base) because module java.base does not export sun.nio.ch to unnamed module
解决如下:
将 intellij 的 project 的版本改成和本地环境一致。
新版的 intellij 一般默认设置 jdk 17
maven no native library is found for os.name=Mac and os.arch=aarch64
将 snappy-java 版本 改为 1.1.8.4,;
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>1.1.8.4</version>
<scope>compile</scope>
</dependency>
然后 删除 .idea,
然后 重新启动 Intellij, 问题即可解决。
java.lang.ClassNotFoundException: xsbt.CompilerInterface
重新 maven clean, 并删除 .idea, 重新打开 Intellij
java: 程序包sun.misc不存在
在这里将 jdk 改成1.8即可解决。
Intellij 无意中的代码修改
如下标记即为无意中修改,
- 以下方式可以回滚
或者打开 Terminal 终端, 直接
git checkout .
生成子类
鼠标定位到父类上,alter+Enter,选择Create Subclass,创建子类
watch
参考链接:
https://www.jetbrains.com/help/idea/debug-tool-window.html#tabs
- Watches: lets you manage watches. By default, watches are shown on
the Variables tab for more efficient use of the screen space. If you
have a lot of watches, consider viewing them in a separate tab.
这边有个 隐藏选项,可以选择是否 “Separate Watches”
Intellij IDEA 分列文件
参考链接:
https://blog.youkuaiyun.com/huangli1466384630/article/details/80109243
恢复:
Intellij idea 设置 console控制台显示内容Size
默认是 1024 KB
FQA
- IDEA 报错
java: JDK isn’t specified for module ‘mvn-helloworld’
删除 .idea;
重新编译 代码;
然后重新打开 Intellij
- scalac: No ‘scala-library*.jar’ in Scala compiler classpath in Scala
SDK Maven: org.scala-lang:scala-library:2.12.15
删除 以下文件, 重新编译, 再次打开 Intellij
.idea/
IndicatorExtract.iml