bat更改java环境变量

通过修改注册表的值来 永久修改。。。下面以修改java_home为例。其实修改java_home就可以达到切换jdk版本的目的:

@echo off&setlocal enabledelayedexpansion
:begin
cls
set/p JAVA_HOME_=请输入新的JAVA_HOME的路径:
if not defined JAVA_HOME_ goto error
for,/f,"skip=4 tokens=1,2,*",%%a,in,(‘reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001

\Control\Session Manager\Environment" /v JAVA_HOME’),do,(
     echo 当前的环境变量为:
     echo %%c
     echo;
     set/p yesno=是否确认将"%JAVA_HOME_%"添加到系统环境变量中去?[Y]/[N]
     if /i "!yesno!"=="y" (
     set regadd=reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v JAVA_HOME /t REG_EXPAND_SZ /d "%JAVA_HOME_%" /f
                )
        goto :eof
)
pause
goto :Eof         
:error
echo 输入错误,请重新输入
pause
goto begin

JDK各版本地址下载和环境变量设置

JDK环境变量配置

JDK环境变量配置的步骤如下:

1.我的电脑–>属性–>高级–>环境变量.

2.配置用户变量:

        a.新建 JAVA_HOME

              C:\Program Files\Java\j2sdk1.5.0 (JDK的安装路径)

        b.新建 PATH

            %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin

        c.新建 CLASSPATH

            .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar

3.测试环境变量配置是否成功:

   开始–>运行–〉CMD

   键盘敲入: JAVAC   JAVA

        出现相应的命令,而不是出错信息,即表示配置成功!

环境变量配置的理解:

  1. PATH环境变量。作用是指定命令搜索路径,在i命令行下面执行命令如javac编译java程序时,它会到PATH变量所指定的路径中查找看是否能找到相应的命令程序。我们需要把jdk安装目录下的bin目录增加到现有的PATH变量中,bin目录中包含经常要用到的可执行文件如javac/java/javadoc等待,设置好PATH变量后,就可以在任何目录下执行javac/java等工具了。

  2. CLASSPATH环境变量。作用是指定类搜索路径,要使用已经编写好的类,前提当然是能够找到它们了,JVM就是通过CLASSPTH来寻找类的。我们需要把jdk安装目录下的lib子目录中的dt.jar和tools.jar设置到CLASSPATH中,当然,当前目录“.”也必须加入到该变量中。

  3. JAVA_HOME环境变量。它指向jdk的安装目录,Eclipse/NetBeans/Tomcat等软件就是通过搜索JAVA_HOME变量来找到并使用安装好的jdk。

Unix环境变量

export JAVA_HOME=/usr/jdk/j2sdk1.4.2_11
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin


JDK、JRE下载地址

Sun公司 最新的JDK下载地址:
http://java.sun.com/javase/downloads/index.jsp

---JDK JRE 6.0---

JDK 6u1(Java(TM) SE Development Kit 6 Update 1 )下载 (56.06 MB,大小为windows版本,下同)
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-6u1-oth-JPR&SiteId=JSC&TransactionId=noreg

JRE 6u1(运行环境,Java(TM) SE Runtime Environment 6 Update 1 ) 下载 (13.16 MB)
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jre-6u1-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 6.0(最初版) Java(TM) SE Development Kit 6
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-6-oth-JPR&SiteId=JSC&TransactionId=noreg

---JDK JRE 5.0---

JDK JRE 5.0 下载导航页面
http://java.sun.com/javase/downloads/index_jdk5.jsp

JDK 5u11 (J2SE(TM) Development Kit 5.0 Update 11 )下载(50.92 MB)
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_11-oth-JPR&SiteId=JSC&TransactionId=noreg

JRE 5.0u11(J2SE(TM) Runtime Environment 5.0 Update 11 ) 下载 (15.80 MB)
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jre-1.5.0_11-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 5.0 最初版(J2SE(TM) Development Kit 5.0 )下载 (43.93 MB)
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0-oth-JPR&SiteId=JSC&TransactionId=noreg

5.0其它版本:

JDK 5u10 (J2SE(TM) Development Kit 5.0 Update 10 )下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_10-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 5u9 (J2SE(TM) Development Kit 5.0 Update 9 )下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_09-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 5u8 (J2SE(TM) Development Kit 5.0 Update 8 )下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_08-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 5u7 (J2SE(TM) Development Kit 5.0 Update 7 )下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_07-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 5u6 (J2SE(TM) Development Kit 5.0 Update 6 )下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_06-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 5u5 (J2SE(TM) Development Kit 5.0 Update 5 )下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_05-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 5u4 (J2SE(TM) Development Kit 5.0 Update 4 )下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_04-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 5u3 (J2SE(TM) Development Kit 5.0 Update 3 )下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_03-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 5u2 (J2SE(TM) Development Kit 5.0 Update 2 )下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=jdk-1.5.0_02-oth-JPR&SiteId=JSC&TransactionId=noreg

---JDK JRE 1.4.2---

JDK JRE 1.4.2 下载导航页面
http://java.sun.com/j2se/1.4.2/download.html

JDK 1.4.2_14 (Java(TM) 2 SDK, Standard Edition 1.4.2_14 ) 下载 (48.89 MB)
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=j2sdk-1.4.2_14-oth-JPR&SiteId=JSC&TransactionId=noreg

JRE 1.4.2_14         ( Java(TM) 2 Runtime Environment, Standard Edition 1.4.2_14 )下载(14.90 MB)
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=j2re-1.4.2_14-oth-JPR&SiteId=JSC&TransactionId=noreg

JDK 1.4.2_03 (Java(TM) 2 SDK, Standard Edition 1.4.2_14 ) 下载
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=j2sdk-1.4.2_03-oth-JPR&SiteId=JSC&TransactionId=noreg

---JDK JRE 1.3.1---

JDK JRE 1.3.1 下载导航页面
http://java.sun.com/j2se/1.3/ja/download.html

JDK 1.3.1 (Java(TM) 2 SDK, Standard Edition 1.3.1_20 )(31.83 MB)
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=j2sdk-1.3.1_20-oth-JPR&SiteId=JSC&TransactionId=noreg

JRE 1.3.1 (Java(TM) 2 Runtime Environment, Standard Edition 1.3.1_20) (5.26 MB)
http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=j2re-1.3.1_20-oth-JPR&SiteId=JSC&TransactionId=noreg

AIX Download and service information

Service and support is only one aspect of what IBM offers an Indep

http://www.ibm.com/developerworks/java/jdk/aix/service.html

(其它版本大家可以根据URL地址和JDK版本推算出来)