现在在Centos7下搭建一下java开发环境,由于自带的java版本为1.7.0且升级到1.8.0后且不带javac等编译工具,所以我打算卸掉重新完整的装一次看能否解决问题.
[root@mycentos shell]# uname -a
Linux mycentos 3.10.0-327.36.2.el7.x86_64 #1 SMP Mon Oct 10 23:08:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
1.先用yum list installed |grep java 查看一下当前安装的JDK
[root@mycentos shell]# yum list installed |grep java
java-1.8.0-openjdk.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-accessibility-debug.x86_64
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-headless-debug.x86_64
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-javadoc-zip-debug.noarch
java-1.8.0-openjdk-src.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-atk-wrapper.x86_64 0.30.4-5.el7 @base
javapackages-tools.noarch 3.4.1-11.el7 @base
python-javapackages.noarch 3.4.1-11.el7 @anaconda
tzdata-java.noarch 2017a-1.el7 @updates
[root@mycentos shell]#
2. 卸载带有@updates标志的所有java组件.
[root@mycentos shell]# yum -y remove java-1.8.0-openjdk*
[root@mycentos shell]# yum -y remove tzdata-java.noarch
分别执行,如结果显示complete并没有任何报错,说明已经成功卸载.
3.确保网络正常情况,查看yum库中的java安装包
[root@mycentos shell]# yum -y list java*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.sohu.com
Installed Packages
javapackages-tools.noarch 3.4.1-11.el7 @base
Available Packages
java-1.6.0-openjdk.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-demo.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-devel.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-src.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.7.0-openjdk.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-accessibility.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-demo.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-devel.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-headless.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.7.0-openjdk-src.x86_64 1:1.7.0.131-2.6.9.0.el7_3 updates
java-1.8.0-openjdk.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-accessibility-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-debug.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-devel-debug.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-headless-debug.i686 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-javadoc-zip-debug.noarch 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.121-0.b13.el7_3 updates
java-atk-wrapper.i686 0.30.4-5.el7 base
java-atk-wrapper.x86_64 0.30.4-5.el7 base
java_cup.noarch 1:0.11a-16.el7 base
java_cup-javadoc.noarch 1:0.11a-16.el7 base
java_cup-manual.noarch 1:0.11a-16.el7 base
javacc.noarch 5.0-10.el7 base
javacc-demo.noarch 5.0-10.el7 base
javacc-javadoc.noarch 5.0-10.el7 base
javacc-manual.noarch 5.0-10.el7 base
javacc-maven-plugin.noarch 2.6-17.el7 base
javacc-maven-plugin-javadoc.noarch 2.6-17.el7 base
javamail.noarch 1.4.6-8.el7 base
javamail-javadoc.noarch 1.4.6-8.el7 base
javassist.noarch 3.16.1-10.el7 base
javassist-javadoc.noarch 3.16.1-10.el7 base
4. 执行安装java-1.8.0-openjdk所有包,大约有18个包(16个+2个依赖包),需要个几分钟时间(网速和镜像资源相关)
[root@mycentos shell]# yum -y install java-1.8.0-openjdk*
同样结果显示complete并没有任何报错,说明已经成功安装.
[root@mycentos shell]# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
[root@mycentos shell]# 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
查看javac显示用法,说明正常,图中标黄是最常用到编译选项,顺便附上这个命令用法的中文版
[root@mycentos Desktop]# javac
用法: javac <options> <source files>
其中, 可能的选项包括:
-g 生成所有调试信息
-g:none 不生成任何调试信息
-g:{lines,vars,source} 只生成某些调试信息
-nowarn 不生成任何警告
-verbose 输出有关编译器正在执行的操作的消息
-deprecation 输出使用已过时的 API 的源位置
-classpath <路径> 指定查找用户类文件和注释处理程序的位置
-cp <路径> 指定查找用户类文件和注释处理程序的位置
-sourcepath <路径> 指定查找输入源文件的位置
-bootclasspath <路径> 覆盖引导类文件的位置
-extdirs <目录> 覆盖所安装扩展的位置
-endorseddirs <目录> 覆盖签名的标准路径的位置
-proc:{none,only} 控制是否执行注释处理和/或编译。
-processor <class1>[,<class2>,<class3>...] 要运行的注释处理程序的名称; 绕过默认的搜索进程
-processorpath <路径> 指定查找注释处理程序的位置
-parameters 生成元数据以用于方法参数的反射
-d <目录> 指定放置生成的类文件的位置
-s <目录> 指定放置生成的源文件的位置
-h <目录> 指定放置生成的本机标头文件的位置
-implicit:{none,class} 指定是否为隐式引用文件生成类文件
-encoding <编码> 指定源文件使用的字符编码
-source <发行版> 提供与指定发行版的源兼容性
-target <发行版> 生成特定 VM 版本的类文件
-profile <配置文件> 请确保使用的 API 在指定的配置文件中可用
-version 版本信息
-help 输出标准选项的提要
-A关键字[=值] 传递给注释处理程序的选项
-X 输出非标准选项的提要
-J<标记> 直接将 <标记> 传递给运行时系统
-Werror 出现警告时终止编译
@<文件名> 从文件读取选项和文件名
下面用vim编辑器,写两个小程序HelloWord.java和HelloString.java,并编译生产.class的字节码文件,然后执行给出结果.
public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello, World!");
}
}
public class HelloString{
static String s1="你好!";
public static void main(String[] args){
String s2="java";
System.out.println(s1);
System.out.println(s2);
}
}
后者主要使用成员变量和局部变量,打印输出.
使用通配符,使用javac命令一次性对上面两个文件进行编译.[root@mycentos shell]# javac -cp ./ Hello*.java
编译成功后注意同时生成的字节码文件
[root@mycentos shell]# java HelloWorld
Hello, World!
[root@mycentos shell]# java HelloString
你好!
java