为什么Java SDK安装程序不设置JAVA_HOME? [英] Why doesn't the Java SDK installer set JAVA_HOME?

查看:334
本文介绍了为什么Java SDK安装程序不设置JAVA_HOME?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


JAVA_HOME = c:\我一直想知道为什么我必须在安装Java SDK后手动设置JAVA_HOME环境变量。程序文件\Java\jdk1.6.0_12


Visual Studio至少提供了一个批处理文件来设置这些环境变量:


调用c:\Program Files\Microsoft Visual
Studio 9.0\VC\vcvarsall.bat


Java有什么类似的东西吗?我正在尝试制作一个构建脚本,应该在安装Java SDK后才能正常工作。我不希望人们在他们的电脑上混淆环境变量。

解决方案

你可以安装和你一样多的Java版本喜欢。



设置修改 本地 环境变量(例如 JAVA_HOME ,因为它可能引用现有的Java安装。



这与所谓的平台相关问题无关。 ;)



由于脚本可能依赖于 JAVA_HOME 来启动自己,这对于新的Java将是灾难性的安装修改 JAVA_HOME :所有这些脚本将突然被一个新的可能不兼容的JVM启动。



Plus ,通过在您的路径中设置 $ JAVA_HOME / bin %JAVA_HOME%/ bin ,您可以动态更改 JAVA_HOME 到您要使用的任何版本的Java,而不用太多与您的PATH变量。






Michael Borgwardt 在评论中发表了有趣的后续问题


但是,这并不能解释为什么安装程序在以前没有设置时不会设置JAVA_HOME。


答案很简单:



设置不能知道如果脚本已经依赖于 JAVA_HOME



含义:一些脚本可以测试 JAVA_HOME 值,如果未设置,请参考其他安装的另一个JVM(不要忘记安装,只能引用复制:JDK / JRE并不总是由安装程序进行安装)



如果您设置了 JAVA_HOME ,那可能会中断某些你的脚本。


不想打扰依赖于env var的假设脚本没有设置声音对我无意义的偏执 - 如果一个脚本那么,那么明确的是,在安装一个JVM之后使用不同的JVM - 没有理由来避免这种情况。


Mmm ... Sweet 。对于每天处理大规模部署问题(对于我店内部的应用程序),我可以向您保证:这是非常理智的偏执狂
对待拥有。

当您部署到(非常)大量的用户时,您不想对其平台和配置做任何假设。 明显的WANTS是我不敢做的假设(或者我将手机重定向到你的身上),你处理愤怒的电话)。



例如,我们有许多脚本启动与Sun的1.4.2 JVM(JAVA_HOME未设置在开发平台上,默认路径直接在脚本中设置),或与JRockit( JAVA_HOME set,因为它是集成,预生产和生产平台上的预期目标)。



但是,由于我们使用的是我们定期安装新的JDK1.6.x它用于启动日食。



假设那些脚本想要他们的 JAVA_HOME 设置...没有任何工作了。



... Robert Grant 将此现场评论者:



您正在描述需要一个特定版本的脚本,但仍然查看全局JAVA_HOME。这只是一个很糟糕的脚本。



虽然这可能是也可能不是真的,正是我的观点:

你不想做任何假设:他们的平台/设置没有假设,也没有对他们的最佳做法的假设。

前者可能声音偏执,后者是普通常识:认为您的产品(这里是JDK设置)不会破坏用户环境中的任何内容,因为用户正确地认为他的脚本会疯狂。






GvS 建议:


或者可以选择这样做,默认情况下禁用


这将意味着在设置屏幕中包含另一个选项,该选项应由用户仔细检查,哪些可能会产生意想不到的后果,即使用户选择它也是如此他知道他在做什么...



根本不值得。


I always wondered why I have to manually set the JAVA_HOME environment variable after installing the Java SDK.

JAVA_HOME=c:\Program Files\Java\jdk1.6.0_12

Visual Studio at least provides a batch file to set these kind of environment variables:

call "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"

Does Java have something similar? I'm trying to make a build script that should simply work after installing the Java SDK. I don't want people to mess with environment variables on their PC.

解决方案

You can install as many versions of Java as you like.

It would be dangerous for the setup to modify a local environment variable such as JAVA_HOME, since it might reference an existing Java installation.

This has nothing to do with an alleged "platform dependent issue". ;)

Since scripts might depend on JAVA_HOME to launch themselves, again, this would be disasterous for a new Java install to modify JAVA_HOME: all those scripts would suddenly have to be launched with a new potentially incompatible JVM.

Plus, by setting $JAVA_HOME/bin or %JAVA_HOME%/bin in your path, you can dynamically change JAVA_HOME to whatever version of Java you want to use without having to much with your PATH variable.


Michael Borgwardt has made in the comments the interesting followup's question

Still, this does not explain why the installer does not set JAVA_HOME when it is not previously set at all.

The answer is simple:

The setup cannot know if a script already depends on JAVA_HOME or not.

Meaning: some scripts could test for JAVA_HOME value, and if not set, refer to another JVM installed elsewhere (and do not forget that by "install", one can only refer to "copied": a JDK/JRE is not always installed by a setup)

If you set JAVA_HOME, that can disrupt the default behavior of some of your scripts.

Not wanting to disturb hypothetical scripts that depend on a env var not being set sound pointlessly paranoid to me - If a script does that, then it clearly WANTS to use a different JVM when one is installed - no reason to avoid that.

Mmm... Sweet. For dealing with massive deployment issues on a daily-basis (for internal application in my shop), I can assure you: it is very sane "paranoid" treat to have.
When you deploy to a (very) large set of users, you do not want to make any assumption about their platform and configurations. "clearly WANTS" is an assumption I would not dare to make (or I redirect my phone to yours ;) and you handle the angry calls).

For instance, we have many scripts which launches with a 1.4.2 JVM from sun (JAVA_HOME not set on development platform, default path set directly in the script), or with 1.4.2 from JRockit (JAVA_HOME set, as it is the intended target on integration, pre-production and production platforms).

But we install regularly the new JDK1.6.x since we use it for launching eclipse.

Assume that those scripts want their JAVA_HOME set... and nothing works anymore.

... To which Robert Grant makes this on-the-spot critic:

You're describing scripts that require one specific version, but still look at global JAVA_HOME. That's just badly thought out scripts.

While that may or may not be true, that also illustrates precisely my point:
"you do not want to make any assumption": no assumption on their platform/settings, and no assumption on their "best practices".
The former may sound paranoid, the latter is plain common-sense: thinking that your product (here a JDK setup) will not break anything on the user's environment because the user has "correctly" thought out his scripts... would be insane.


GvS suggests:

Or it could just have option to do it, disabled by default

That would mean another option to include in the setup screens, option which should be carefully reviewed by the user, and which may have unintended consequences, even when the user selects it thinking he knows what he is doing...

It is simply not worth it.

这篇关于为什么Java SDK安装程序不设置JAVA_HOME?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆