今天在使用Ubuntu编译Android的时候遇到一个jdk配置的问题,记之以备遗忘,以备时光。
===========
配置JDK
使用docker创建我的容器,使用了别人的Ubuntu镜像,打开以后发现已经安装了一个版本的JDK
root@0517854c0269:/# java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1~14.04-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
我需要的JDK版本是1.7,执行如下命令进行了安装:
apt-get install openjdk-7-jdk
安装完以后就需要配置了,因为查看了一下发现默认的JDK版本还是原来已经安装的1.8版本,查找了一下,发现可以使用update-alternatives命令进行配置。如下:
update-alternatives --config javac
update-alternatives --config javap
update-alternatives --config javah
update-alternatives --config java
配置完以后,查看java版本,已经设置好了:
root@0517854c0269:/# java -version
java version "1.7.0_201"
OpenJDK Runtime Environment (IcedTea 2.6.17) (7u211-2.6.17-0ubuntu0.1)
OpenJDK 64-Bit Server VM (build 24.201-b00, mixed mode)
root@0517854c0269:/# javac -version
javac 1.7.0_201
root@0517854c0269:/# javap -version
1.7.0_201
root@0517854c0269:/# javah -version
javah version "1.7.0_201"
还看到一个比较简单粗暴的方法,就是把之前的jdk统统卸载,然后重新安装,命令如下:
//查看安装的jdk包
dpkg --list | grep -i jdk
//移除 openjdk包
apt-get purge openjdk*
除此之外有个有趣的问题,发现不同版本的Ubuntu在下载JDK包时,速度真是天差地别。使用Ubuntu12.04下载openjdk-7-jdk,速度是MB级别的,如果用Ubuntu16.04下载,就只有10几KB每秒。。所以自己在搭建环境的时候,建议与原厂推荐的环境版本保持一致,可能会少一些坑。
===========
javac javap javah
javac 编译工具
javap 反编译工具
javah 自动生成JNI头文件
root@0517854c0269:/# javac -help
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
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source 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
-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
root@0517854c0269:/# javap -help
Usage: javap <options> <classes>
where possible options include:
-help --help -? Print this usage message
-version Version information
-v -verbose Print additional information
-l Print line number and local variable tables
-public Show only public classes and members
-protected Show protected/public classes and members
-package Show package/protected/public classes
and members (default)
-p -private Show all classes and members
-c Disassemble the code
-s Print internal type signatures
-sysinfo Show system info (path, size, date, MD5 hash)
of class being processed
-constants Show static final constants
-classpath <path> Specify where to find user class files
-bootclasspath <path> Override location of bootstrap class files
root@0517854c0269:/# javah -help
Usage:
javah [options] <classes>
where [options] include:
-o <file> Output file (only one of -d or -o may be used)
-d <dir> Output directory
-v -verbose Enable verbose output
-h --help -? Print this message
-version Print version information
-jni Generate JNI-style header file (default)
-force Always write output files
-classpath <path> Path from which to load classes
-bootclasspath <path> Path from which to load bootstrap classes
<classes> are specified with their fully qualified names
(for example, java.lang.Object).
update-alternatives
软件版本管理命令
可参考链接:
https://blog.csdn.net/hellocsz/article/details/82701689
root@0517854c0269:/# update-alternatives --help
Usage: update-alternatives [<option> ...] <command>
Commands:
--install <link> <name> <path> <priority>
[--slave <link> <name> <path>] ...
add a group of alternatives to the system.
--remove <name> <path> remove <path> from the <name> group alternative.
--remove-all <name> remove <name> group from the alternatives system.
--auto <name> switch the master link <name> to automatic mode.
--display <name> display information about the <name> group.
--query <name> machine parseable version of --display <name>.
--list <name> display all targets of the <name> group.
--get-selections list master alternative names and their status.
--set-selections read alternative status from standard input.
--config <name> show alternatives for the <name> group and ask the
user to select which one to use.
--set <name> <path> set <path> as alternative for <name>.
--all call --config on all alternatives.
<link> is the symlink pointing to /etc/alternatives/<name>.
(e.g. /usr/bin/pager)
<name> is the master name for this link group.
(e.g. pager)
<path> is the location of one of the alternative target files.
(e.g. /usr/bin/less)
<priority> is an integer; options with higher numbers have higher priority in
automatic mode.
Options:
--altdir <directory> change the alternatives directory.
--admindir <directory> change the administrative directory.
--log <file> change the log file.
--force allow replacing files with alternative links.
--skip-auto skip prompt for alternatives correctly configured
in automatic mode (relevant for --config only)
--verbose verbose operation, more output.
--quiet quiet operation, minimal output.
--help show this help message.
--version show the version.