简体   繁体   English

如何使Eclipse更耐Java更新的更好方法

[英]A better way how to make Eclipse resistant to Java updates

It is a know problem, when you update Java, JDK or JRE, on Windows Eclipse will likely to fail to start as it points to outdated JDK/JRE folder. 这是一个已知的问题,当您更新Java,JDK或JRE时,Windows上的Eclipse可能无法启动,因为它指向过时的JDK / JRE文件夹。 Fix is relatively simple, it was discussed and solved on several threads like here or here . 修复相对简单,它在这里这里的几个线程上进行了讨论和解决

But I found those solutions unsatisfyingly inflexible. 但我发现这些解决方案不够灵活。 This solutions suggest to manually fix path in eclipse.ini to something like: 这个解决方案建议手动将 eclipse.ini路径修复为:

-vm C:\Program Files\Java\<jdk-version-just-installed>\bin\javaw.exe

This means you have to do it after every update, again and again. 这意味着您必须在每次更新后一次又一次地执行此操作。 If you update JDK frequently, and everyone should to have latest security patches, that makes it very annoying. 如果经常更新JDK,并且每个人都应该拥有最新的安全补丁,这会让人非常讨厌。

I expect that after a smart installation every Java program would just run out of box without any manual step involved; 我希望在智能安装之后,每个Java程序都可以在没有任何手动步骤的情况下运行。 any solution less than that I would not consider satisfactory. 任何低于我认为不满意的解决方案。

I can think of two ways: 我可以想到两种方式:

  • using environmental (system) variable like JAVA_HOME. 使用环境(系统)变量,如JAVA_HOME。 Can eclipse.ini reference environmental variables? eclipse.ini能参考环境变量吗?

  • using symbolic link pointing to the latest JDK. 使用指向最新JDK的符号链接。 And if you wonder, yes, Windows with NTFS support symlinks. 如果你想知道,是的,Windows与NTFS支持符号链接。

Both ways however need some cooperation from the installer, both JAVA_HOME or symlink as to be updated to the new value. 但是,这两种方式都需要安装程序的一些合作,JAVA_HOME或符号链接都要更新为新值。 Automatically of course, otherwise there would be no reason why to have them in the first place. 当然是自动的,否则就没有理由把它们放在首位。 Please correct me if I am wrong, but JDK/JRE installation on linux does exactly that, provides and updates symlink to latest JDK/JRE. 如果我错了,请纠正我,但在linux上安装JDK / JRE就是这样,提供并更新符号链接到最新的JDK / JRE。 Why not Windows installer? 为什么不安装Windows?

Is there a hidden parameter, option or a toggle in Java install tool doing that? Java安装工具中有隐藏的参数,选项或切换吗?
If not, is there a better, an alternative installation tool? 如果没有,是否有更好的替代安装工具?
Can Eclipse launcher itself find a latest Java? Eclipse启动器本身能找到最新的Java吗?
Is there a better eclipse.ini parameter for that? 那个有更好的eclipse.ini参数吗?

The purpose of specifying the VM in either eclipse.ini or on the command line is to isolate it from system updates. eclipse.ini或命令行中指定VM的目的是将其与系统更新隔离。 For example, in the past it has been a big problem that some programs install their own JVM and include it on the system PATH (Oracle was particularly bad about this). 例如,在过去,一些程序安装自己的JVM并将其包含在系统PATH(Oracle特别糟糕)中是一个大问题。 So the entire idea is to isolate Eclipse from those kinds of changes; 因此,整个想法是将Eclipse与这些变化隔离开来; it should not care what other JVMs you have on your system, it refers to a "known" good one for running Eclipse. 它不应该关心你的系统上的其他JVM,它指的是运行Eclipse的“已知”好的JVM。

Another alternative is to place a JVM directly under the Eclipse installation directory, in a directory named jre , as documented here . 另一种方法是将JVM直接放在Eclipse安装目录下的jre目录中,如此处所述 I don't personally ever do that, however; 但是,我个人并不这样做; I find it to be unnecessary and cumbersome. 我发现这是不必要和麻烦的。

What I do that would probably help you is to not install JVM updates into separate directories with names that reflect the actual update version. 我所做的可能对您有帮助的是将JVM更新安装到具有反映实际更新版本的名称的单独目录中。 Instead, I install JDKs into a consistent place based on the major java version. 相反,我基于主要的 Java版本将JDK安装到一致的位置。 For example: 例如:

/Java/
    /JDK/
        /1.7/
            /bin/
            <etc...>
        /1.8/
            /bin/
            <etc...>

That way, in eclipse.ini (or any other place a need to refer to a particular JVM) I just use /Java/JDK/1.8 and that will continue to work no matter how many updates I install into that location. 这样,在eclipse.ini (或任何其他需要引用特定JVM的地方)我只使用/Java/JDK/1.8 ,无论我在该位置安装了多少更新,它都将继续工作。

What we do to avoid this problem: We have custom dedicated JDK's for our development environment (for eclipse and for our products), which are not 'attached' to the system. 我们如何避免这个问题:我们为我们的开发环境(对于eclipse和我们的产品)提供了定制的专用JDK,它们不会“附加”到系统中。 We're using softlinks eg ../app/jdk which links to a specific jdk, for intellij we have a ../app/intellij-jdk softlink. 我们正在使用软链接,例如../app/jdk链接到特定的jdk,对于intellij我们有一个../app/intellij-jdk软链接。

Not sure who to do it in windows, but in linux you download the gzip and extract it, withing messing up your system, like paths, I think for windows you can only download the installer, but it's possible to only extract the actual software from the executable. 不确定是谁在windows中做到这一点,但是在linux中你下载了gzip并将其解压缩,弄乱了你的系统,比如路径,我认为对于windows你只能下载安装程序,但它可能只从中提取实际的软件可执行文件。

Older Windows JDK installers used to copy java.exe and javaw.exe (and also javavm.dll I think) in c:\\windows\\system32 to make them available in the default path. 较旧的Windows JDK安装程序用于复制c:\\windows\\system32 java.exejavaw.exe (以及我认为的javavm.dll ),以使它们在默认路径中可用。

In recent installers, a symbolic link is created for java.exe , javaw.exe and javaws.exe in C:\\ProgramData\\Oracle\\Java\\javapath . 在最近的安装程序中,为C:\\ProgramData\\Oracle\\Java\\javapath java.exejavaw.exejavaws.exe创建了符号链接 This means that these executables will point always to the most recent JDK update. 这意味着这些可执行文件将始终指向最新的JDK更新。

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

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