Suleka_28
Suleka_28

Reputation: 2919

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

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

enter image description here

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:

enter image description here

I get the following error:

Error: JAVA_HOME is not defined correctly.

But when I type:

echo $JAVA_HOME

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

Upvotes: 0

Views: 1347

Answers (2)

Suleka_28
Suleka_28

Reputation: 2919

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

Upvotes: 0

user272735
user272735

Reputation: 10648

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.

Upvotes: 1

Related Questions