JAVA_HOME 在尝试运行 Ballerina 代码时在 Ubuntu 上未正确定义。

huangapple go评论84阅读模式
英文:

JAVA_HOME is not defined correctly on Ubuntu when trying to run Ballerina code?

问题

我已经在环境变量文件中设置了JAVA_HOME,如下所示。

我还从源代码构建了Ballerina,并根据Ballerina文档提取了包含运行时和工具的ZIP文件。然而,当我尝试将此分发作为Ballerina SDKIntelliJ IDEA中,甚至在终端中运行Ballerina程序时,我收到以下错误:

出现以下错误:

错误:JAVA_HOME未正确定义。

但是当我输入:

echo $JAVA_HOME <br/>

我得到以下输出:

/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

我做错了什么?

注意:Ballerina版本:jballerina-tools-2.0.0-Preview3-SNAPSHOT

英文:

I have already set JAVA_HOME in the environment variables file as shown below.

JAVA_HOME 在尝试运行 Ballerina 代码时在 Ubuntu 上未正确定义。

I also built ballerina from the source and extracted the zip with the Runtime and the tools as per the Ballerina documentation. However when I try to give this distribution as the Ballerina SDK in IntelliJ IDEA or even in the Terminal and try to run a Ballerina program as shown below:

JAVA_HOME 在尝试运行 Ballerina 代码时在 Ubuntu 上未正确定义。

I get the following error:

Error: JAVA_HOME is not defined correctly.

But when I type:<br/>

echo $JAVA_HOME <br/>

I get the following output:

/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

What am I doing wrong?

Note: Ballerina Version: jballerina-tools-2.0.0-Preview3-SNAPSHOT

答案1

得分: 1

你的 JAVA_HOME 环境变量的值是错误的。它不应该指向可执行文件,而应该指向Java安装的位置(即一个目录)。

在你的情况下,正确的值似乎是:

/usr/lib/jvm/java-8-openjdk-amd64

也可以参考如何设置Java的JAVA_HOME?

普通的Ballerina 1.2分发版不需要JAVA_HOME,但由于你正在构建一个预览版本,你的情况可能不同。

英文:

The value of your JAVA_HOME environment variable is wrong. It should not to point to an executable but to the location (i.e. a directory) of the Java installation.

In your case the correct value seems to be:

/usr/lib/jvm/java-8-openjdk-amd64

See also e.g. How to set JAVA_HOME for Java?.

Normal Ballerina 1.2 distribution doesn't require JAVA_HOME but this might be different in your case as you're building a preview release.

答案2

得分: 0

@user272735部分正确,但您可以看到我已经在环境文件中添加了正确的Java主目录路径。实际问题是,在更改环境文件中的Java主目录路径并运行以下命令时,我正在terminator上工作。

source /etc/environment

但我尝试在普通终端上运行Ballerina代码,其中路径更改尚未注册

如何解决:

我还必须在终端中运行以下命令。然后,当我回显Java路径时,它打印了环境文件中的路径,并且Ballerina代码也正常运行。

source /etc/environment
英文:

what @user272735 was partly correct but you can see that I have added the correct Java Home path in the environment file. Actually the problem was that I was working on terminator when changing the java home path in the environment file and running the below command.

 source /etc/environment

But I was trying to run the ballerina code in the plain-old Terminal where the path change was not registered yet.

How to resolve:

I had to run the below command in the Terminal as well. Then when I echoed the java path it printed the one in the environment file and the ballerina code also ran without a problem.

source /etc/environment

huangapple
  • 本文由 发表于 2020年7月28日 19:08:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63132731.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定