Environment variables for java installation

后端 未结 14 1020
清歌不尽
清歌不尽 2020-11-22 00:52

How to set the environment variables for Java in Windows (the classpath)?

相关标签:
14条回答
  • 2020-11-22 00:54

    Under Linux: http://lowfatlinux.com/linux-environment-variables.html

    And of course, you can retrieve them from Java using:

    String variable = System.getProperty("mykey");
    
    0 讨论(0)
  • 2020-11-22 00:56

    For deployment better to set up classpath exactly and keep environment clear. Or at *.bat (the same for linux, but with correct variables symbols):

    CLASSPATH="c:\lib;d:\temp\test.jar;<long classpath>"
    CLASSPATH=%CLASSPATH%;"<another_logical_droup_of_classpath" 
    java -cp %CLASSPATH% com.test.MainCLass
    

    Or at command line or *.bat (for *.sh too) if classpath id not very long:

    java -cp "c:\lib;d:\temp\test.jar;<short classpath>"
    
    0 讨论(0)
  • 2020-11-22 00:58

    In Windows inorder to set

    Step 1 : Right Click on MyComputer and click on properties .

    Step 2 : Click on Advanced tab

    alt text

    Step 3: Click on Environment Variables

    alt text

    Step 4: Create a new class path for JAVA_HOME

    alt text

    Step 5: Enter the Variable name as JAVA_HOME and the value to your jdk bin path ie c:\Programfiles\Java\jdk-1.6\bin and

    NOTE Make sure u start with .; in the Value so that it doesn't corrupt the other environment variables which is already set.

    alt text

    Step 6 : Follow the Above step and edit the Path in System Variables add the following ;c:\Programfiles\Java\jdk-1.6\bin in the value column.

    Step 7 :Your are done setting up your environment variables for your Java , In order to test it go to command prompt and type

     java   
    

    who will get a list of help doc

    In order make sure whether compiler is setup Type in cmd

      javac
    

    who will get a list related to javac

    Hope this Helps !

    0 讨论(0)
  • 2020-11-22 01:06

    Java SE Development Kit 8u112 on a 64-bit Windows 7 or Windows 8

    Set the following user environment variables (== environment variables of type user variables)

    • JAVA_HOME : C:\Program Files\Java\jdk1.8.0_112
    • JDK_HOME : %JAVA_HOME%
    • JRE_HOME : %JAVA_HOME%\jre
    • CLASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
    • PATH : your-unique-entries;%JAVA_HOME%\bin (make sure that the longish your-unique-entries does not contain any other references to another Java installation folder.

    Note for Windows users on 64-bit systems:

    Progra~1 = 'Program Files'
    Progra~2 = 'Program Files(x86)'
    

    Notice that these environment variables are derived from the "root" environment variable JAVA_HOME. This makes it easy to update your environment variables when updating the JDK. Just point JAVA_HOME to the fresh installation.

    There is a blogpost explaining the rationale behind all these environment variables.

    Optional recommendations

    • Add an user environment variable JAVA_TOOL_OPTIONS with value -Dfile.encoding="UTF-8". This ensures that Java (and tools such as Maven) will run with a Charset.defaultCharset() of UTF-8 (instead of the default Windows-1252). This has saved a lot of headaches when wirking with my own code and that of others, which unfortunately often assume the (sane) default encoding UTF-8.
    • When JDK is installed, it adds to the system environment variable Path an entry C:\ProgramData\Oracle\Java\javapath;. I anecdotally noticed that the links in that directory didn't get updated during an JDK installation update. So it's best to remove C:\ProgramData\Oracle\Java\javapath; from the Path system environment variable in order to have a consistent environment.
    0 讨论(0)
  • 2020-11-22 01:07

    In programming context you can execute SET command (SET classpath=c:\java) or Right click on your computer > properties > advanced > environment variables.

    In a batch file you can use

    SET classpath=c:\java
    java c:\myapplication.class
    
    0 讨论(0)
  • 2020-11-22 01:08

    For Windows:

    • Right click on 'My Computers' and open 'Properties'.
    • In Windows Vista or Windows 7, go to "Advanced System Settings". Else go to next step.
    • Go to 'Advanced Tab' and click on Environment Variables button.
    • Select 'Path' under the list of 'System Variables', and press Edit and add C:\Program Files\java\jdk\bin after a semicolon.
    • Now click on 'new' button under system variables and enter 'JAVA_HOME' as variable name and path to jdk home directory (ex. 'C:\Program Files\Java\jdk1.6.0_24' if you are installing java version 6. Directory name may change with diff. java versions) as variable_value.
    0 讨论(0)
提交回复
热议问题