linux下配置JDK环境变量

来源:互联网 发布:3d怎么优化模型减少面 编辑:程序博客网 时间:2024/04/29 19:32

搞死了一个ubuntu系统后,终于搞定了JDK环境变量,下面分享下配置过程

1、下载

我用的版本是java8 linux 32位(i586)

下载地址:http://www.oracle.com/technetwork/java/index.html

2、安装

在图形界面下,直接解压缩到桌面即可

如果不想放在桌面,可以放在别的文件夹下

但我是放在桌面的,文件夹就叫做jdk1.8.0

3、配置

配置是最关键的一步,如果不严格按照如下输入,会导致系统无法启动

打开terminal

依次输入

export JAVA_HOME=/home/roy/Desktop/jdk1.8.0

备注:我的用户名叫roy,根据安装系统时的不同设置,将roy改成自己的用户名。如果使用了其他路径,请输入自己的路径,注意严格按照大小写输入

export PATH=$JAVA_HOME/bin:$PATH

备注:最后的$PATH十分重要,这句话相当于把原来的PATH内容完整保留下来,在前面加上JAVA的路径。我第一次就是因为没有保留这句话,导致系统无法启动

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

备注:如果系统装了其他语言的编译工具,需要在这句话后面再加上    :$CLASSPATH    ,原因同上

4、测试

在terminal中输入

javac

然后看到输出

Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath <path>          Specify where to find user class files and annotation processors
  -cp <path>                 Specify where to find user class files and annotation processors
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
  -processorpath <path>      Specify where to find annotation processors
  -parameters                Generate metadata for reflection on method parameters
  -d <directory>             Specify where to place generated class files
  -s <directory>             Specify where to place generated source files
  -h <directory>             Specify where to place generated native header files
  -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release
  -target <release>          Generate class files for specific VM version
  -profile <profile>         Check that API used is available in the specified profile
  -version                   Version information
  -help                      Print a synopsis of standard options
  -Akey[=value]              Options to pass to annotation processors
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system
  -Werror                    Terminate compilation if warnings occur
  @<filename>                Read options and filenames from file

证明配置成功


0 0