java 使用cordova构建时无效的JAVA_HOME

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33946953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:20:16  来源:igfitidea点击:

Invalid JAVA_HOME when build with cordova

javaandroidcordovaopensuse

提问by Rafael Soufraz

I am trying to emulate an app on my device with cordova in OpenSuse Leap 42.1.
But when I tried to emulate the app with the cordova runI get the error below:

我正在尝试使用 OpenSuse Leap 42.1 中的cordova 在我的设备上模拟应用程序。
但是当我尝试用 模拟应用程序时,cordova run我收到以下错误:

cordova run
Running command: /home/soufraz/Projects/apps/myproject/platforms/android/cordova/run 
ERROR: Error: Failed to run "java -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: /usr/lib64/jvm/java-1.8.0-openjdk-1.8.0

ERROR running one or more of the platforms: Error: /home/soufraz/Projects/apps/myproject/platforms/android/cordova/run: Command failed with exit code 2
You may not have the required environment or OS to run this project

I have the java installed and the paths set in ~/.profile.
Which is the configuration error in my environment?

我已经安装了 java 并且在~/.profile.
哪个是我的环境中的配置错误?

Below my .profile:

在我的下面.profile

JAVA_HOME=/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0
export JAVA_HOME

ANDROID_HOME=/home/soufraz/Install/android-sdk-linux
export ANDROID_HOME

PATH=$PATH:$ANDROID_HOME:$JAVA_HOME

Info about java version:

关于java版本的信息:

java -version
openjdk version "1.8.0_60"
OpenJDK Runtime Environment (build 1.8.0_60-b27)
OpenJDK 64-Bit Server VM (build 25.60-b23, mixed mode)

And here the list of jvm folder:

这里是 jvm 文件夹列表:

ls -l
total 28
lrwxrwxrwx 1 root root 24 Nov 12 11:28 java-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0
drwxr-xr-x 1 root root  6 Nov 12 11:28 java-1.7.0-openjdk-1.7.0
drwxr-xr-x 1 root root  6 Nov 11 17:26 java-1.8.0-openjdk-1.8.0
lrwxrwxrwx 1 root root 21 Nov 11 17:26 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root 27 Nov 12 11:28 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx 1 root root 28 Nov 12 11:28 jre-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0/jre
lrwxrwxrwx 1 root root 27 Nov 11 17:26 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root 28 Nov 11 17:26 jre-1.8.0-openjdk -> java-1.8.0-openjdk-1.8.0/jre
lrwxrwxrwx 1 root root 29 Nov 11 17:26 jre-openjdk -> /etc/alternatives/jre_openjdk

[edit]View tree with three levels:

[编辑]具有三个级别的视图树:

tree -L 3
.
├── java-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0
├── java-1.7.0-openjdk-1.7.0
│?? └── jre
│??     ├── bin
│??     └── lib
├── java-1.8.0-openjdk-1.8.0
│?? └── jre
│??     ├── bin
│??     └── lib
├── jre -> /etc/alternatives/jre
├── jre-1.7.0 -> /etc/alternatives/jre_1.7.0
├── jre-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0/jre
├── jre-1.8.0 -> /etc/alternatives/jre_1.8.0
├── jre-1.8.0-openjdk -> java-1.8.0-openjdk-1.8.0/jre
└── jre-openjdk -> /etc/alternatives/jre_openjdk

采纳答案by Rafael Soufraz

In my specific case, I remove and reinstall all java packages and add one (for 'instinct'):
I removed:
java-1_8_0-openjdk
java-1_8_0-openjdk-headless
java-1_8_0-openjdk-plugin

在我的特定情况下,我删除并重新安装所有 java 包并添加一个(对于“本能”):
我删除了:
java-1_8_0-openjdk
java-1_8_0-openjdk-headless
java-1_8_0-openjdk-plugin

And added:
java-1_8_0-openjdk
java-1_8_0-openjdk-headless
java-1_8_0-openjdk-plugin
java-1_8_0-openjdk-devel<<-- luckily I hit it

并补充说:
java-1_8_0-openjdk
java-1_8_0-openjdk-headless
java-1_8_0-openjdk-plugin
java-1_8_0-openjdk-devel<<--幸运的是我击中了它

The bin inside main folder appears. With javac and another things.
Thank you guys!

出现主文件夹内的 bin。用 javac 和别的东西。
感谢你们!

回答by dan

Cordova needs a JDKnot a JRE, since it is checking for javac. See check_reqs.jsline 86. From your comments you are saying that "Inside this path, there isn't the bin folder" in a JDKyou should have a bindirectory!

Cordova 需要一个JDKnot a JRE,因为它正在检查javac. 请参阅check_reqs.js86。根据您的评论,您是说“在此路径中,没有 bin 文件夹”,JDK您应该有一个bin目录!

回答by Bilal Shah

Your path should be like this

你的路径应该是这样的

PATH=$PATH:$ANDROID_HOME/bin:$JAVA_HOME/bin

PATH=$PATH:$ANDROID_HOME/bin:$JAVA_HOME/bin

and than export PATH

然后 export PATH

回答by Mateusz Was

It's a bit of misunderstanding with java-X_X_X-openjdk packages. Especially when you are used to default Oracle notation.

对 java-X_X_X-openjdk 包有点误解。特别是当您习惯于默认 Oracle 表示法时。

The JDK part is confusing, because OpenJDK is a project of an open-source implementation of the Java Platformand not a JDK - package actually allowing you to develop in Java. (more precise info here: http://openjdk.java.net/install/index.html)

JDK 部分令人困惑,因为OpenJDK 是 Java 平台的开源实现项目,而不是 JDK - 实际上允许您使用 Java 进行开发的包。(这里有更准确的信息:http: //openjdk.java.net/install/index.html

TLDR:

域名注册地址:

  1. java-X_X_X-openjdk is Oracle's JRE equivalent.

  2. java-X_X_X-openjdk-devel is Oracle's JDK equivalent.

  1. java-X_X_X-openjdk 是 Oracle 的 JRE 等价物。

  2. java-X_X_X-openjdk-devel 是 Oracle 的 JDK 等价物。

回答by BEJGAM SHIVA PRASAD

Verifying java & JDK installations resolved my problem.. Install java & JDK and try..

验证 java 和 JDK 安装解决了我的问题.. 安装 java 和 JDK 并尝试..

To build and run apps, you need to install SDKs for each platform you wish to target. Alternatively, if you are using browser for development you can use browser platform which does not require any platform SDKs.

要构建和运行应用程序,您需要为要定位的每个平台安装 SDK。或者,如果您使用浏览器进行开发,则可以使用不需要任何平台 SDK 的浏览器平台。

To check if you satisfy requirements for building the platform:

要检查您是否满足构建平台的要求:

$ cordova requirements
Requirements check results for android:
Java JDK: installed .
Android SDK: installed
Android target: installed android-19,android-21,android-22,android-23,Google Inc.:Google APIs:19,Google Inc.:Google APIs (x86 System Image):19,Google Inc.:Google APIs:23
Gradle: installed

Requirements check results for ios:
Apple OS X: not installed
Cordova tooling for iOS requires Apple OS X
Error: Some of requirements check failed