简体   繁体   English

在Windows中安装和切换java 7和java 8

[英]install and switch between java 7 and java 8 in windows

I am on widows and also using eclipse. 我在寡妇和使用日食。 Currently I am using java 7. Now I want to use java 8. but i cannot uninstall java 7 as some of my old projects are working in java 7. 目前我正在使用java 7.现在我想使用java 8.但我无法卸载java 7,因为我的一些旧项目在java 7中工作。

So how can I install both java version at same time and switch between these versions. 那么如何同时安装两个java版本并在这些版本之间切换。

I want only some particular projects will use java 8. 我只想要一些特定的项目将使用java 8。

Well after installing both JDK 7 & JDK 8, There are two scenarios. 在安装JDK 7和JDK 8之后,有两种情况。

1) If you are using Eclipse to run your program 1)如果您使用Eclipse来运行程序

In Eclipse just go to project->Properties->java complier->set compliance level to 1.8 or 1.7 accordingly 在Eclipse中,只需转到project-> Properties-> java complier->将合规级别设置为1.8或1.7

2) If you are running your program using Command Prompt 2)如果使用命令提示符运行程序

In this case, you have to enter following commands before compiling your program 在这种情况下,您必须在编译程序之前输入以下命令

  set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_102
  set PATH=C:\Program Files\Java\jdk1.8.0_102\bin;%PATH%
  java -version

you can also make a batch file of the same. 你也可以制作相同的批处理文件。 just copy and paste to notepad and save it with the .bat extension 只需复制并粘贴到记事本并使用.bat扩展名保存

Create a script that changes the JAVA_HOME environment accordingly, for example: 创建一个相应更改JAVA_HOME环境的脚本,例如:

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_11
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.6.0_11\bin;%PATH%
echo Display java version
java -version

Source: https://blogs.oracle.com/pranav/entry/switch_between_different_jdk_v 资料来源: https//blogs.oracle.com/pranav/entry/switch_between_different_jdk_v

Install both JDKs in your system and for any project if you want to use jdk 1.8. 如果要使用jdk 1.8,请在系统和任何项目中安装两个JDK。 Do this 做这个

Right click on that project->Properties->java complier->set compliance level to 1.8

If you are using Eclipse, you can set the compiler preferences with the Java version you want to use for every project. 如果您使用的是Eclipse,则可以使用要为每个项目使用的Java版本设置编译器首选项。

Go to Window -> Preferences -> Java -> Compiler and there you can change the Java version. 转到Window -> Preferences -> Java -> Compiler ,您可以在那里更改Java版本。

This way, you can update your PC to Java 8 and you'll have no problem with the older projects. 这样,您可以将PC更新为Java 8,并且您对旧项目没有任何问题。

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

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