正确安装java 8和java 7

编程入门 行业动态 更新时间:2024-10-10 11:29:56
本文介绍了正确安装java 8和java 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在我的Windows 7机器上安装了JDK 1.7,在安装JDK 1.8 u20之后我遇到以下错误:

I've JDK 1.7 installed on my windows 7 machine and after installing JDK 1.8 u20 I'm having following error:

C:\>java -version Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion' has value '1.8', but '1.7' is required. Error: could not find java.dll Error: Could not find Java SE Runtime Environment.

我的 PATH 变量指向旧版本(即1.7)。

My PATH variable points to the older version (i.e. 1.7).

这里有什么问题以及我如何使用java 8和java 7?

What is wrong here and how I could use java 8 along with java 7?

推荐答案

问题是Java 8会安装很多你并不需要的东西:

The problem is that Java 8 installs a lot of stuff that you don't really need:

  • \windows\system32 包含Java 8 java.exe,javaw.exe 和 javaws.exe 即可。您的路径可能在开头附近有 system32 ,因此这些路径默认情况下会运行。

  • \windows\system32 contains Java 8 java.exe, javaw.exe and javaws.exe. Your path probably has system32 near the beginning, so these tend to be run by default.

系统路径变量以 C:\programdata \Oracle \ Java \ _javapath 开头。此文件夹包含 java.exe , javaw.exe 和 javaws.exe 作为JRE 8可执行文件的符号链接。

The system path variable starts with C:\programdata\Oracle\Java\javapath. This folder contains java.exe, javaw.exe and javaws.exe as symlinks to the JRE 8 executables.

我删除了 system32 文件并删除了 C:\programdata \\ \\ Oracle \ Java来自系统路径的\ javapath 。这似乎解决了这个问题。我现在可以通过将 JAVA_HOME 和 PATH 指向相应的文件夹来切换版本。

I've deleted the system32 files and removed C:\programdata\Oracle\Java\javapath from the system path. This seems to cure the problem. I can now switch versions by pointing JAVA_HOME and PATH to the appropriate folders.

Oracle似乎是决心让很难运行多个版本。这对于JRE来说是可以理解的,但是对于JDK来说这很疯狂,因为开发人员几乎总是需要多个版本的Java。

Oracle, it seems, are determined to make it hard to run multiple versions. This is understandable with the JRE, but it's crazy with JDKs, as developers almost always need multiple versions of Java.

编辑:我发现这个批处理脚本对于切换JDK非常有用。用法:jdk.bat 6 | 7 | 8。您可能需要编辑Java的安装位置。

I find this batch script is useful for switching JDKs. Usage: jdk.bat 6|7|8. You might have to edit the installation location for Java.

@echo off if "%1"=="" goto report set _version=%1 shift if "%1"=="DBG" shift & echo on set _command=%1 %2 %3 %4 %5 set _jdkdir= set _jdkver= for /D %%f in ("C:\Program Files\java\"jdk1.%_version%.*) do call :found "%%f" if "%_jdkdir%"=="" goto notfound set java_home=C:\Program Files\java\%_jdkdir% call :javapath path %new_path% goto :report :javapath setlocal enabledelayedexpansion set _jdirs= for /D %%j in ("C:\Program Files\java\*") do set _jdirs=!_jdirs!#%%~fj\bin set _jdirs=%_jdirs%# set _javabin=%java_home%\bin set _fpath="%PATH:;=" "%" call :checkpath %_fpath% endlocal & set new_path=%_javabin% goto :eof :checkpath if _%1==_ goto :eof echo %_jdirs% | find /i "#%~1#" 1>nul 2>&1 set _err=%errorlevel% if not %_err%==0 set _javabin=%_javabin%;%~1 if %_err%==0 echo Removed %~1 from path shift goto :checkpath :report javac -version %_command% goto :eof :notfound echo No JDK matching [C:\Program Files\java\jdk1.%_version%.*] found. goto :eof :found set _jdkdir=%~n1%~x1 for /F "tokens=2,3 delims=." %%a in ("%_jdkdir%") do set _jdkver=1.%%a.%%b goto :eof

更多推荐

正确安装java 8和java 7

本文发布于:2023-11-25 20:18:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631209.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!