简体   繁体   English

来自root的mac os java版本是不同的

[英]mac os java version from root is different

after installing jdk7u5 for mac os I got different java-versions for "normal" user and root. 在为mac os安装jdk7u5之后,我为“普通”用户和root获得了不同的java版本。

java -version gives me the 7. java -version给了我7。

sudo java -version gives me the 6. sudo java -version给了我6。

I've looked up in the /System/Library/Frameworks/JavaVM.framework/Versions/ found that there are some links. /System/Library/Frameworks/JavaVM.framework/Versions//System/Library/Frameworks/JavaVM.framework/Versions/发现有一些链接。 After I resolved the links to the real Directory I tried it again with the whole path. 解决了指向真实目录的链接后,我再次尝试了整个路径。

/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java -version -> 7 /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java -version - > 7

sudo /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java -version -> 6 sudo /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java -version - > 6

Same with javac! 和javac一样!

Hope you guys could help me! 希望你们能帮助我!

Under OSX /usr/bin/java locates the java version to be used by looking at what you chose using /Applications/Utilities/Java Preferences.app . 在OSX / usr / bin / java下,通过使用/Applications/Utilities/Java Preferences.app查看您选择的内容来查找要使用的Java版本。 The files ths uses are also updated by the Oracle updater. 所使用的文件也由Oracle更新程序更新。

As you have to drag the versions manually to set Java 1.7 you will have only set this for the user you run it as ie not root. 由于您必须手动拖动版本以设置Java 1.7,因此您只能为运行它的用户设置此项,即不是root用户。 To set it for root I ran the app as sudo /Applications/Utilities/Java\\ Preferences.app/Contents/MacOS/Java\\ Preferences and moved 1.7 to the top. 要将其设置为root,我将应用程序作为sudo /Applications/Utilities/Java\\ Preferences.app/Contents/MacOS/Java\\ Preferences ,并将1.7移至顶部。

As far as I can see the files the app updates are in ~/Library/Preferences/ByHost/com.apple.java.JavaPreferences.<hex number>.plist where <hex number> is machine related. 据我所知,应用程序更新的文件位于~/Library/Preferences/ByHost/com.apple.java.JavaPreferences.<hex number>.plist其中<hex number>与机器相关。 Root's home directory is /var/root so I now have /var/root/Library/Preferences/ByHost/com.apple.java.JavaPreferences.<hex number>.plist Root的主目录是/ var / root所以我现在有/var/root/Library/Preferences/ByHost/com.apple.java.JavaPreferences.<hex number>.plist

Caught the same issue on Mac OS X 10.7.5 + JRE 1.6.0_43 + JDK 1.7.0_17. 在Mac OS X 10.7.5 + JRE 1.6.0_43 + JDK 1.7.0_17上遇到了同样的问题。

  • java -version => 1.7 java -version => 1.7
  • sudo java -version => 1.6 sudo java -version => 1.6

Open java control panel with sudo, this fixes the problem: 使用sudo打开java控制面板,这可以解决问题:

  • sudo /usr/bin/javaws -viewer sudo / usr / bin / javaws -viewer

It appears that the java version used by the link you specified depends on the JAVA_VERSION environment variable. 您指定的链接使用的Java版本似乎取决于JAVA_VERSION环境变量。 Could it be that this variable is set for your user, but will be cleared by sudo ? 可能是这个变量是为你的用户设置的,但是会被sudo清除吗? In that case, explicitely unsetting it for the user or setting it for root should help to keep them in sync. 在这种情况下,明确地为用户取消设置或将其设置为root应该有助于使它们保持同步。 Of course, you might also replace the /A/ by the actual version you want to execute. 当然,您也可以将/A/替换为您要执行的实际版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM