我们使用cordova的时候需要安装其他的应用依赖,在进行环境检查的时候出现如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [root@localhost myapp]# cordova requirements Requirements check results for android: Java JDK: not installed Failed to find 'JAVA_HOME' environment variable. Try setting it manually. Android SDK: not installed Failed to find 'ANDROID_SDK_ROOT' environment variable. Try setting it manually. Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory. Android target: not installed Command failed with ENOENT: android list target spawn android ENOENT Gradle: not installed Could not find gradle wrapper within Android SDK. Could not find Android SDK directory. Might need to install Android SDK or set up 'ANDROID_SDK_ROOT' env variable. Requirements check results for ios: Apple macOS: not installed Error: Cordova tooling for iOS requires Apple macOS Some of requirements check failed [root@localhost myapp]# |
通过上面我们可以知道java jdk并没有安装,这个时候我们需要安装java jdk。
第一步:我们检查下环境系统,在这里我们以centos为例。
1 2 | [root@localhost ~]# cat /etc/system-release CentOS Linux release 8.2.2004 (Core) |
第二步:我们得知时centos 8,在centos 8系统中推荐使用dnf来代替yum安装,至于为什么centos8这样做,你可以百度一下,这里不再赘述。
OpenJDK是一个免费和开源的Java平台实现,根据GNU通用公共许可证版本2授权的标准版本。通过下面的命令我们可以看到安装的java 11.
1 | sudo dnf install java-11-openjdk-devel |
1 2 3 4 5 | [root@localhost myapp]# java -version openjdk version "11.0.9.1" 2020-11-04 LTS OpenJDK Runtime Environment 18.9 (build 11.0.9.1+1-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.9.1+1-LTS, mixed mode, sharing) [root@localhost myapp]# |
第三步:查看java的安装位置
1 2 3 | [root@localhost myapp]# which java /usr/bin/java [root@localhost myapp]# |
第四步:配置java环境变量。
1 2 3 4 5 | cat > /etc/profile.d/java11.sh <<EOF export JAVA_HOME=\$(dirname \$(dirname \$(readlink \$(readlink \$(which javac))))) export PATH=\$PATH:\$JAVA_HOME/bin export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar EOF |
第五步:重新加载配置文件。
1 | source /etc/profile.d/java11.sh |
第六步:测试java代码,这里我们写一个简单的helloword程序,使用命令行如下创建代码文件。
1 2 3 4 5 6 7 | cat > hello_world.java <<EOF public class helloworld { public static void main(String[] args) { System.out.println("Hello Java World!"); } } EOF |
第七步:运行java代码。
1 2 3 | [root@localhost test]# java hello_world.java Hello Java World! [root@localhost test]# |
第八步:如果你安装有多个java版本。可以进行设置使用哪个版本。
1 2 | sudo alternatives --list sudo alternatives --config java |
1 2 3 4 5 6 7 8 9 10 11 | [root@localhost myapp]# sudo alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.275.b01-1.el8_3.x86_64/jre/bin/java) + 2 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.9.11-3.el8_3.x86_64/bin/java) Enter to keep the current selection[+], or type selection number: 2 [root@localhost myapp]# |
这里我们使用第二个版本java 11。接下来我们使用配置javac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@localhost test]# sudo alternatives --config javac There is 1 program that provides 'javac'. Selection Command ----------------------------------------------- *+ 1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.9.11-3.el8_3.x86_64/bin/javac) Enter to keep the current selection[+], or type selection number: 1 [root@localhost test]# java -version openjdk version "11.0.9.1" 2020-11-04 LTS OpenJDK Runtime Environment 18.9 (build 11.0.9.1+1-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.9.1+1-LTS, mixed mode, sharing) [root@localhost test]# javac -version javac 11.0.9.1 |
第九步:安装完成检查,Java JDK: installed 11.0.9.1 。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | [root@localhost myapp]# cordova requirements Requirements check results for android: Java JDK: installed 11.0.9.1 Android SDK: not installed Failed to find 'ANDROID_SDK_ROOT' environment variable. Try setting it manually. Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory. Android target: not installed Command failed with ENOENT: android list target spawn android ENOENT Gradle: not installed Could not find gradle wrapper within Android SDK. Could not find Android SDK directory. Might need to install Android SDK or set up 'ANDROID_SDK_ROOT' env variable. Requirements check results for ios: Apple macOS: not installed Error: Cordova tooling for iOS requires Apple macOS Some of requirements check failed [root@localhost myapp]# |
文章不错交个朋友