[TOC]
问题表现
idea 每次运行java单测和tomcat的时候都会出现以下报错
objc[3648]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java (0x10d19c4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10ea194e0).
One of the two will be used.
Which one is undefined.
stackoverflow答案
stackoverflow 上解释这是jdk官方承认的bug,但是只是显示问题,不影响编码。相关链接
The problem is fixed in Java 9 and in Java 8 update 152.
You can find all the details here:
IDEA-170117 "objc: Class JavaLaunchHelper is implemented in both ..." warning in Run consoles
It's the old bug in Java on Mac that got triggered by the Java Agent being used by the IDE when starting the app. This message is harmless and is safe to ignore. Oracle developer's comment:
The message is benign, there is no negative impact from this problem since both copies of that class are identical (compiled from the exact same source). It is purely a cosmetic issue.
The problem is fixed in Java 9 and in Java 8 update 152.
If it annoys you or affects your apps in any way (it shouldn't), the workaround for IntelliJ IDEA is to disable idea_rt
launcher agent by adding idea.no.launcher=true
into idea.properties
(Help
| Edit Custom Properties...
). The workaround will take effect on the next restart of the IDE.
具体处理
下载Java 8 update 152
设置运行的jre
总结
-
idea设置jdk和jre是完全独立的。
image.png
jre是运行时配置,如上图,jdk是编码和编译用的,设置如下。 -
删除jdk
下载了jdk 1.8.152并配置环境变量后,idea还是使用1.8.0_121.jdk。于是把1.8.0_121.jdk删了。
删除方法:/Library/Java/JavaVirtualMachines/ 直接删除掉对应的jdk -
删除java
继续上一步,删除1.8.0_121.jdk后,java还是不会自动使用jdk 1.8.152,于是继续删除java,删除方法 。 -
设置idea强制使用1.8.152版本的jdk
image.png
设置方法:vim /Applications/IntelliJ IDEA.app/Contents/Info.plist
综上:
- 由于一开始没有找到idea设置运行时jvm的地方,一直以为idea会自动使用jdk使用的jre,因此不断删原来可能会让idea读取到老jre的地方。
- 没事不要升级idea,java版本,本次出问题的idea是2017.1,之前没有这个问题。
网友评论