jdk1.6,jdk1.7 Coexistence

Source: Internet
Author: User

Of course, when installing, remember to choose a different installation directory, after installation, you can switch between the development tools (such as Eclipse) the different compilation environment and the running environment. In fact, as long as the installation of Eclipse has its own jdk1.3-1.6 compilation environment.

After installing multiple versions of JDKJDK8 GA at the same time on Mac, small partners like to run, eager to experience a Java8 lambda and other new features, but the current Java enterprise application of the main version is JDK6, JDK7. Therefore, I need to have jdk8,jdk7,jdk6 on my computer at the same time. JDK6 and JDK7 mainly do some product code verification, as well as play some of their own open-source projects, JDK8 is purely early adopters, who called us a hate programmer.
Target
At the command line, you can easily switch to the corresponding Java version by command ' Jdk6 ', ' jdk7 ', ' jdk8 ', and the default initial setting is Jdk7.
Practices
1. Install all the JDK first:
* Mac comes with JDK6, installed in directory:/system/library/java/javavirtualmachines/1.6.0.jdk/.
* Jdk7,jdk8 will need to download and install the corresponding version on the Oracle website. The default path for your own JDK installation is:/LIBRARY/JAVA/JAVAVIRTUALMACHINES/JDK1.8.0.JDK
2. Configure the path to Java_home in the bash configuration file in the user directory BASHRC:
Exportjava_6_home=/system/library/ java/javavirtualmachines/1.6. 0.jdk/contents/homeexport java_7_home=< Span class= "regexp" >/library/java/javavirtualmachines/jdk1.7.0.jdk/contents/homeexport java_8_home=/library/java/ JAVAVIRTUALMACHINES/JDK1. 8.0.jdk/contents/homeexport java_home= $JAVA _7_home         
3. Create the alias command to dynamically switch Java_home configuration
Alias jdk8=' export java_home= $JAVA _8_home 'alias jdk7=' export java_home= $JAVA _7_home 'alias jdk6=  ' Export java_home= $JAVA _6_home '    
Authentication
Cnxnliu: Versions Xnliu$ Java-versionjava Version"1.6.0_65"JapanTM)SERuntimeEnvironment (Build1.6.0_65-b14-462-11m4609)JavaHotSpot (TM)64-BitServerVM (Build20.65-b04-462, mixed mode) cnxnliu:versions xnliu$ jdk8 cnxnliu:versions xnliu$ Java-versionjava Version  "1.8.0" java (TM) se runtime environment (build 1.8.0-b132) java hotspot (tm) 64-bit server span class= "constant" >VM (build 25.0-b70, mixed mode) cnxnliu:versions xnliu$         

different versions of JDK coexistence under Windows1. Install Jdk7, remove Java.exe, Javaw.exe, Javac.exe from the C:\Windows\System32 directory. 2. Install the JDK8, and remove the system environment variable in path C:\ProgramData\Oracle\Java\javapath. 3. Edit and launch the Eclipse.bat file.

@echoOff

SetJava_home_7=F:\eclipse\java7
::Echo java_home_7=%Java_home_7%

SetJava_home_8=F:\eclipse\java8
::Echo Java_home_8=%Java_home_8%

SetJava_home=%Java_home_7%
::Echo Java_home=%Java_home%

SetCLASSPATH=.; %Java_home%\lib;%Java_home%\lib\tools.Jar
::Echo CLASSPATH=%CLASSPATH%

:: echo path=% path%
set Path=%< Span class= "PLN" >path%;%java_home%\b< Span class= "KWD" >in;%java_home%\jre\b< Span class= "KWD" >in :: echo path=%path%

start f:\eclipse\eclipse\eclipse exe

:: cmd

In addition, this approach eliminates the need to manually set environment variables after the JDK7 installation is complete.

JDK1.6 and JDK1.7 coexistence and Eclipse error

Background:

The JDK has been released to version 1.8, and as a "nostalgic" programer, I haven't been paying much attention to the new version. It was always the version of the JDK that the project needed, and I always thought that if the project was too dependent on the JDK version, it would be too shit for development and design! These days for some reason you need to switch to the old version of the project to do something. The old version (known as V1) was developed by JDK1.6, and the new version (known as V2) uses JDK1.7. Now it takes two versions of the JDK to coexist, something that I thought was simple, and it turned out to be a bunch of problems. It's embarrassing!!

Problem:

1. Jdk1.6,copy was installed eclipse,get the project code, but the company's eclipse plugin could not be run!

2. Specifies that eclipse starts with a JDK of 1.6, error code 13, unable to start eclipse!

3. The eclipse startup problem and plug-in issues are fixed, the JDK version is specified for the project (two workspaces), but the 1.7 version does not work, and the "main class error cannot be found or cannot be loaded" is displayed!

Originally this event is very simple, but because of some small details of the mistake to cause oneself around the boss a circle. It seems that the details determine where the success or failure is applicable!

Summarize:

1. The JDK is allowed to exist on a large version, but it is not allowed on a minor version;

2. Eclipse itself is a Java program, which we all know, but why can't we find a JAVAW process when eclipse starts? That's because eclipse calls Jvm.dll by default, and if we specify that the startup parameter is Javaw.exe then a javaw.exe process is started.

3.Eclipse will also rely on a certain version of the JDK, which depends on which version of Eclipse you use, generally it is backwards compatible, that is, JDK1.5 can run, JDK1.6, JDK1.7 can also. However, there is no guarantee that the Eclipse plugin will work well on different versions of the JDK, such as our plugins, which are very dependent on the JDK version.

4.Eclipse can specify the JDK version that compiles and runs the Java program, which is different from the JDK that it runs on, or that it has nothing to do with the same JDK.

5.Eclipse 32-bit and 64-bit, must match 32-bit and 64-bit JDK, otherwise will error!

Process:

(1) The Eclipse plugin does not work:

Reason: The JDK version used at eclipse startup does not conform to plug-in requirements.

method: Specify the JKD for Eclipse startup and add the following parameters to the Eclipse.ini file.

-VM D:\JDK1.6\bin\javaw.exe

Result: The following error is reported when starting:

(2) Eclipse boot error, code 13

Cause: The path to the VM parameter specified in Eclipe.ini is incorrect, or the number of bits in eclipse and the number of JDK bits is inconsistent.

method: Download the 32-bit JDK, reinstall, and specify the VM parameters.

PS: The official website of the JDK is not pure, unexpectedly to the registry to write something, and then can not uninstall, only download the uninstall tool, Force uninstall clear the registry.

Result: After reinstalling the compliant JDK, Eclipse is able to boot, The first 1.6 installed and then the V1 project is available, then 1.7 is installed, the JDK1.7 path is added to eclipse, and the compile level is specified for V2, but the following error has occurred:

(3) Eclipse specifies JDK1.7 compile level error, unable to find main class

Reason: finally after some repeated search, only to find that the eclipse under the new JDK1.7 when a parameter filled the wrong!!

In the Defalut VM arguments more than fill in a JDK1.7. Cause every time eclipse runs, it will look for the JDK1.7 class. O (╯-╰) o

method: Remove the Defalut vmarguments parameter.

PS: If the JDK or JRE is not installed, Eclipse startup will report the following error:

Last Spit Trough:

The company plug-in is so closely tied to the JDK, it's shit!. And not a guide to the document, wasted nearly a day of time!

Then is Java unexpectedly also is not pure, the Windows version unexpectedly also has the update program, also will go to register the table to write things!!! How can you do this!

Implementing JAVA6 and Java8 coexistence solutions on WindowsIssue Background

The JDK environment applied to the company's project was 1.6, and recently, when I was learning IntelliJ idea in the SDK multi-environment configuration, I wanted to install Jdk1.8 as a learning base. So the problem comes, the company project extension does not support jdk1.8, in order to meet the company's project development environment, but also to meet the needs of learning jdk1.8, of course, not every time the JDK installation and uninstallation, need to explore another new method.

Analyze problems

In order to M.F.B. s solve the current problem, my idea is to install both jdk1.6 and jdk1.8 in Windows, switching between them in the middle without having to repeat the installation and uninstallation multiple times, which is simple and convenient.

Solution Ideas
    1. First step: Before installation, the native JDK environment is jdk1.6, execute: java -version , display the current JDK version is 1.6

    1. Step Two: Install jdk1.8 and let two jdk coexist. 安装教程是:直接 下一步 and 下一步after the installation is complete, set the following settings for the JDK environment variables:

      JAVA8_HOME =jdk1.8的安装路径
      JAVA6_HOME =jdk1.6的安装路径
      JAVA_HOME = %JAVA6_HOME% (注意:如果你想切换jdk,就在此处设置即可)

After setting the environment variable as shown:

    1. Step three: Add %JAVA_HOME%\bin to the environment variable path, as shown in the following path:

After the

environment variable is configured, the following issues occur after installation:
with java-version  to view the display, the JDK appears as: jdk1.8
Analysis:  
The current JDK version is 1.8, which is unscientific, because the environment variables configured in the Java_home is the path of 1.6, the view version should be 1.6 of the right, now become 1.8,JDK environment variable has not been changed, through the query after the discovery of the problem:

  install jdk1. 8jdk1. 6 re-installed jdk1. 8java.javaw.javaws. three executables copied to c:\windows\system32 because this directory takes precedence over >windows The environment variable priority set.   

解决方案:

删除C:\Windows\System32目录下的java.exe,删除即可。

注意: If there is one in path  C:\ProgramData\Oracle\Java\javapath;  , delete it. Otherwise, the argument is wrong.

    • Fourth step: When the above configuration is complete, open a new  cmd  window, view the JDK version display is normal, in the environment variable switch java_home value is:  JAVA_HOME=%JAVA8_HOME%  , view the JDK version, successfully switch. :

Summarize

After being abused by the Community editor, I finally wrote the tutorial, (or blame myself, not familiar with the Community editor, will be more practice later). Bitter languish night finally out of the night, PS: is a cat point awake, although very low, or to thank him, 阿里嘎多!! 
This tutorial also has a lot of shortcomings, not considered the place, I hope that we work together to improve it, so that it is more perfect. Thank you! In this article I refer to the following links:

Https://coderwall.com/p/gbek2g/java-6-and-java-7-on-windows
Http://blog.sina.com.cn/s/blog_437ee9d00101isob.html
http://blog.163.com/[email protected]/blog/static/68117214201521211149742/

This article is for learning and communication purposes only and does not represent the Turing community perspective. Non-commercial reprint please indicate as translator, source, and keep the original link of this article

jdk1.6,jdk1.7 Coexistence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.