背景
maven构建报错
[ERROR] 不再支持源选项 6。请使用 8 或更高版本。
[ERROR] 不再支持目标选项 6。请使用 8 或更高版本。
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
thrift打包完成!
iTerm执行mvn -v
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /usr/local/Cellar/maven/3.9.6/libexec
Java version: 21.0.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "14.1.1", arch: "x86_64", family: "mac"
执行ll /usr/local/bin/ | grep mvn,发现指向的是本地安装的maven,而非idea自带的maven
处理方案
先参考https://blog.csdn.net/weixin_44203158/article/details/111478439,修改完之后仍报错
Maven支持的Java version是21.0.1,与Idea的java版本不一样,需要修改成一致的
方案1
修改vim ~/.zshrc
export JAVA_HOME=/usr/local/Cellar/openjdk@8/1.8.0-392/libexec/openjdk.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
export M2_HOME=/usr/local/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin
执行source ~/.zshrc,再看mvn -v,此时Maven的java版本就是环境变量设置的了
执行mvn deploy后仍旧报错javafx.util不存在,原因是:iTerm使用的是OpenJDK,需要改成Oracle JDK
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
OpenJDK 不包含 JavaFX,因为 JavaFX 不是 Java SE 的一部分。JavaFX 是 Oracle 的一个商业产品,它在 Oracle JDK 中可用,但并未包含在 OpenJDK 中。如果你需要使用 JavaFX,你可以单独下载并添加到你的项目中。Oracle JDK 8 包含了 JavaFX。但从 JDK 11 开始,JavaFX 被剥离出 Oracle JDK,成为了一个独立的开源项目 OpenJFX。如果你使用 JDK 11 或更高版本,你需要单独下载并添加 JavaFX SDK 到你的项目中。
方案2
把iTerm的maven版本换成idea自带的,通过软连接的方式把idea的maven地址链接到/usr/local/bin/mvn【参考:https://blog.csdn.net/MrYushiwen/article/details/107687576】
sudo ln -s /Users/jiayueyuanfang/Library/Application\ Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/232.10203.10/IntelliJ\ IDEA\ CE.app/Contents/plugins/maven/lib/maven3/bin/mvn /usr/local/bin/mvn
然后修改vim ~/.zshrc
export MAVEN_HOME=/Users/jiayueyuanfang/Library/Application\ Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/232.10203.10/IntelliJ\ IDEA\ CE.app/Contents/plugins/maven/lib/maven3
export PATH=$PATH:$MAVEN_HOME/bin
执行source ~/.zshrc,再执行mvn -v,发现Maven home已经更换
Apache Maven 3.9.2 (c9616018c7a021c1c39be70fb2843d6f5f9b8a1c)
Maven home: /Users/jiayueyuanfang/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/232.10203.10/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
再执行ll /usr/local/bin/ | grep mvn,已经软链接到idea的地址
lrwxr-xr-x 1 root wheel 160B 12 11 20:38 mvn -> /Users/jiayueyuanfang/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/232.10203.10/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/bin/mvn