developer tip

/ usr / libexec / java_home에서 반환 된 Mac OS의 기본 Java VM을 어떻게 변경할 수 있습니까?

copycodes 2020. 8. 19. 19:48
반응형

/ usr / libexec / java_home에서 반환 된 Mac OS의 기본 Java VM을 어떻게 변경할 수 있습니까?


(이것이 SU에서 계속되어야하는지 확신 할 수 없었습니다. 마이그레이션은 확실히 옵션이지만 더 많은 프로그래머가 여기에서 질문을 읽고 여기에 있습니다).

Mac OS X 10.8.4를 실행 중이며 Apple의 JDK 1.6.0_51과 Oracle의 JDK 1.7.0_25가 설치되어 있습니다. 최근에 필요한 일부 시험판 소프트웨어에 대해 Oracle의 1.8 프리뷰 JDK를 설치했습니다. 이제 / usr / libexec / java_home을 실행하면 다음과 같이 표시됩니다.

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (4):
    1.8.0, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
    1.7.0_25, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home
    1.6.0_51-b11-457, x86_64:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_51-b11-457, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

큰.

그러나 다음을 실행합니다.

$ java -version

보고:

java version "1.8.0-ea"

즉, Java의 기본 버전은 현재 시험판 버전이므로 일부 "일반"패키지 (제 경우에는 VisualVM)가 중단됩니다.

JAVA_HOME응용 프로그램을 시작하면 명령 줄 (예 :)에서 시작할 때도 환경 변수가 무시되기 때문에 설정할 수 없습니다 $ open /Applications/VisualVM.app.

그렇다면 내 JVM 주문 기본 설정을 전역 적으로 설정할 수있는 편집 할 수있는 파일이 있습니까?

(단순히 작동하지 않기 때문에 Java 환경 설정 패널을 시작하라고 말하지 마십시오. 유용한 정보가 포함되어 있지 않으며 내가 설치 한 4 개의 JVM 중 하나만 나열됩니다.)

업데이트 :

Oracle JVM은 /Library/Java/JavaVirtualMachines. JDK 1.8 디렉토리의 이름을 바꾸어도 jdk1.8.0.jvm.xyz아무것도 변경되지 않습니다. java_home여전히 올바른 위치에 있으며 / usr / bin / java를 실행하면 여전히 1.8 JVM이 실행됩니다. 이것은 synlink 등의 문제가 아닙니다.

비슷한 질문에 대한 답변

이 답변 은 java_home에서 Java 버전을 제거하는 해킹의 양을 제공 하지만 java_home이 기본값을 선택 하는 방법 과 사용자가 비파괴 적으로 설정할 수 있는지 여부에 대한 질문에 여전히 대답하지 않습니다 .


나는 JAVA_HOME당신이 할 수있는 최선 이라고 생각 합니다. 명령 줄 도구 는 해당 환경 변수를 좋아 java하고 javac존중하므로 명령 줄 도구가 Java 7을 사용하도록하기 위해 /usr/libexec/java_home -v '1.7*'입력 할 적절한 값을 제공하는 데 사용할 수 있습니다 JAVA_HOME.

export JAVA_HOME="`/usr/libexec/java_home -v '1.7*'`"

그러나 표준 더블 클릭 가능한 애플리케이션 번들은 아래 /Library/Java설치된 JDK를 전혀 사용하지 않습니다 . .appApple을 사용하는 이전 스타일 번들 JavaApplicationStub은에서 Apple Java 6을 사용 하며 번들 JRE없이 AppBundler로/System/Library/Frameworks 빌드 된 새로운 스타일 의 번들 은 스터브 코드에 하드 코딩되어 변경 될 수없는 "공개"JRE를 사용합니다. 두 개의 다른 공용 JRE를 동시에 설치할 수 없습니다./Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home


편집 : VisualVM을 구체적으로 살펴 봤습니다 . 다운로드 페이지 에서 "애플리케이션 번들"버전을 사용하고 있다고 가정 하고이 특정 앱은 AppBundler 애플리케이션이 아니라 대신 기본 실행 파일이 번호를 호출하는 셸 스크립트입니다. 다른 쉘 스크립트와 다양한 구성 파일을 읽습니다. 기본적으로 /Library/Java7u10 이상인 경우 최신 JDK를 선택 하거나 Java 7 설치가 업데이트 9 이하인 경우 Java 6을 사용합니다. 그러나 쉘 스크립트에서 로직을 풀면 구성 파일을 사용하여 특정 JDK를 지정할 수있는 것처럼 보입니다.

줄을 포함하는 텍스트 파일을 만듭니다 ~/Library/Application Support/VisualVM/1.3.6/etc/visualvm.conf(1.3.6을 사용중인 VisualVM의 버전으로 대체).

visualvm_jdkhome="`/usr/libexec/java_home -v '1.7*'`"

그러면 8 대신 Java 7을 선택하게됩니다.


나도 거기에 있었고 /usr/libexec/java_home작동 방식을 어디에서나 검색 했지만 나열되는 사용 가능한 Java 가상 머신을 결정하는 방법에 대한 정보를 찾을 수 없었습니다.

나는 약간의 실험을 해 보았고 단순히 a를 실행하고 거기에서 찾은 모든 런타임 ls /Library/Java/JavaVirtualMachines을 검사 한다고 생각합니다 ./<version>/Contents/Info.plist.

그런 다음 Info.plist에 포함 된 키를 기준으로 내림차순 으로 정렬하고 JVMVersion기본적으로 첫 번째 항목을 기본 JVM으로 사용합니다.

우리가 할 수있는 유일한 일은 plist를 변경하는 것입니다. sudo vi /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Info.plist그런 다음 JVMVersion을에서 1.8.0와 같이 상단이 아닌 하단으로 정렬하는 다른 것으로 수정합니다 !1.8.0.

다음과 같은 것 :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    ...
    <dict>
            ...
            <key>JVMVersion</key>
            <string>!1.8.0</string>   <!-- changed from '1.8.0' to '!1.8.0' -->`

그런 다음 목록 상단에서 마술처럼 사라집니다.

/usr/libexec/java_home -verbose
Matching Java Virtual Machines (3):
    1.7.0_45, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
    1.7.0_09, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home
    !1.8.0, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home

이제 로그 아웃 / 로그인 후 다음을 수행해야합니다.

java -version
java version "1.7.0_45"

:-)

Of course I have no idea if something else breaks now or if the 1.8.0-ea version of java still works correctly.

You probably should not do any of this but instead simply deinstall 1.8.0.

However so far this has worked for me.


It's actually pretty easy. Let's say we have this in our JavaVirtualMachines folder:

  • jdk1.7.0_51.jdk
  • jdk1.8.0.jdk

Imagine that 1.8 is our default, then we just add a new folder (for example 'old') and move the default jdk folder to that new folder. Do java -version again et voila, 1.7!


It's pretty simple, if you don't mind rolling up your sleeves... /Library/Java/Home is the default for JAVA_HOME, and it's just a link that points to one of:

  • /System/Library/Java/JavaVirtualMachines/1.?.?.jdk/Contents/Home
  • /Library/Java/JavaVirtualMachines/jdk1.?.?_??.jdk/Contents/Home

So I wanted to change my default JVM/JDK version without changing the contents of JAVA_HOME... /Library/Java/Home is the standard location for the current JVM/JDK and that's what I wanted to preserve... it seems to me to be the easiest way to change things with the least side effects.

It's actually really simple. In order to change which version of java you see with java -version, all you have to do is some version of this:

cd /Library/Java
sudo rm Home
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home ./Home

I haven't taken the time but a very simple shell script that makes use of /usr/libexec/java_home and ln to repoint the above symlink should be stupid easy to create...

Once you've changed where /Library/Java/Home is pointed... you get the correct result:

cerebro:~ magneto$ java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM)
64-Bit Server VM (build 25.60-b23, mixed mode)

Oracle's uninstallation instructions for Java 7 worked for me.

Excerpt:

Uninstalling the JDK To uninstall the JDK, you must have Administrator privileges and execute the remove command either as root or by using the sudo(8) tool.

Navigate to /Library/Java/JavaVirtualMachines and remove the directory whose name matches the following format:*

/Library/Java/JavaVirtualMachines/jdk<major>.<minor>.<macro[_update]>.jdk

For example, to uninstall 7u6:

% rm -rf jdk1.7.0_06.jdk


A bit late but as this is an ongoing issue with Mac OSX...

The simplest solution I found was to simply remove the OpenJDK stuff that Apple installs. Every time an update of Mac OSX arrives it gets installed and you'll need to remove it again.

This works really well if you develop apps for Google App Engine on your mac using Java. The OpenJDK does not work well and the Java version that comes with the Mac OSX Yosemite upgrade will make the Eclipse Plug-in for App Engine crash on every deployment with the helpful error: "Read timed out".


I tested "jenv" and other things like setting "JAVA_HOME" without success. Now i and endet up with following solution

function setJava {
    export JAVA_HOME="$(/usr/libexec/java_home -v $1)"
    launchctl setenv JAVA_HOME $JAVA_HOME
    sudo ln -nsf "$(dirname ${JAVA_HOME})/MacOS" /Library/Java/MacOS 
    java -version
}

(added to ~/.bashrc or ~/.bash.profile or ~/.zshrc)

And calling like that:

setJava 1.8

java_home will handle the wrong input. so you can't do something wrong. Maven and other stuff will pick up the right version now.


Edit: this information is for visualvm specifically, not for any other java app

As mentioned by others, you need to modify the visualvm.conf

For the latest version of JvisualVM 1.3.6 on Mac, the install directories have changed.

It is currently in /Applications/VisualVM.app/Contents/Resources/visualvm/etc/visualvm.conf.

However this may depend on where you have installed VisualVM. The easiest way to find where your VisualVM is to start it, and then look at the process using:

ps -ef | grep VisualVM

You will see something like:

... -Dnetbeans.dirs=/Applications/VisualVM.app/Contents/Resources/visualvm/visualvm...

You want to take the netbeans.dir property and look up a directory and you will find the etc folder.

Uncomment this line in the visualvm.conf and change the path to the jdk

visualvm_jdkhome="/path/to/jdk"

Additionally, if you are having slowness with your visualvm and you have a lot of memory, I would suggest greatly increasing the amount of memory available and running it in server mode:

visualvm_default_options="-J-XX:MaxPermSize=96m -J-Xmx2048m -J-Xms2048m -J-server -J-XX:+UseCompressedOops -J-XX:+UseConcMarkSweepGC -J-XX:+UseParNewGC -J-XX:NewRatio=2 -J-Dnetbeans.accept_license_class=com.sun.tools.visualvm.modules.startup.AcceptLicense -J-Dsun.jvmstat.perdata.syncWaitMs=10000 -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.d3d=false"

I had a similar situation, and the following process worked for me:

  1. In the terminal, type

    vi ~/.profile
    
  2. Then add this line in the file, and save

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk<version>.jdk/Contents/Home
    

    where version is the one on your computer, such as 1.7.0_25

  3. Exit the editor, then type the following command make it become effective

    source ~/.profile 
    

Then type java -version to check the result

    java -version 

What is .profile? From:http://computers.tutsplus.com/tutorials/speed-up-your-terminal-workflow-with-command-aliases-and-profile--mac-30515

.profile file is a hidden file. It is an optional file which tells the system which commands to run when the user whose profile file it is logs in. For example, if my username is bruno and there is a .profile file in /Users/bruno/, all of its contents will be executed during the log-in procedure.


MacOS uses /usr/libexec/java_home to find the current Java Version. One way to bypass is to change the plist file as explained by @void256 above. Other ways is to take the backup of the java_home and replace it with your own script java_home having the code
echo $JAVA_HOME

Now export the JAVA_HOME to the desired version of the SDK by adding the following commands to the ~/.bash_profile. export JAVA_HOME="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home" launchctl setenv JAVA_HOME $JAVA_HOME /// Make the environment variable global

Run the command source ~/.bash_profile to the run the above commands.

Anytime one needs to change the JAVA_HOME he can reset the JAVA_HOME value in the ~/.bash_profile file.


I wanted to change default java version form 1.6* to 1.7*. I tried the following steps and it worked for me:

  • Removed link "java" from under /usr/bin
  • Created it again, pointing to the new location:

ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java java

  • verified with "java -version"

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

참고URL : https://stackoverflow.com/questions/17885494/how-can-i-change-mac-oss-default-java-vm-returned-from-usr-libexec-java-home

반응형