ant - JAVA_HOME is not defined correctly - java

I have installed java with the command sudo apt-get install openjdk-7-jdk and set the java home and path.But when I am trying to use ant I
JAVA_HOME is not defined correctly.
We cannot execute /usr/local/java/jre1.7.0_60/bin/java
Please help me how to resolve this error.
which java ----> /usr/bin/java
java -version ---->java version "1.6.0_31"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1ubuntu1~0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
echo $JAVA_HOME -----> /usr/local/java/jre1.7.0_60

I had same problem than you. Try using Oracle jdk instead openjdk
To change OpenJdk by Oracle JDK you can do (you have to download oracle jdk first):
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.6.0_37/bin/java" 1
Here you have a detailed explanation:
http://hendrelouw73.wordpress.com/2012/11/09/how-to-install-oracle-java-6-0-37-on-ubuntu-12-04-linux/
You can set your environment by doing:
vi /etc/environment
in my case I did:
PATH="/usr/lib/jvm/java-6-sun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/usr/lib/jvm/java-6-sun/"
and it solved my problem

Ant requires JDK and you have installed JRE. So ant is throwing such an error.
So, just Uninstall JRE and then install JDK, this will solve your error.

Related

Cordova picking up wrong version of java

I am trying to run
cordova build android
It gives the following error
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/home/bappaditya/Softwares/android-studio (recommended setting)
ANDROID_HOME=/home/bappaditya/Softwares/android-studio (DEPRECATED)
Requirements check failed for JDK 8 ('1.8.*')! Detected version: 12.0.2
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.
I can see that it has picked up ANDROID_HOME and ANDROID_SDK_ROOT but not the correct version of java
My current environment
>java -version
openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)
>echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64
>echo $PATH
/home/bappaditya/.cargo/bin:/opt/gradle/gradle-5.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/bappaditya/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin
As you can see the JAVA 8 is installed and set as default. Why cordova complaining about java version?
It seems cordova uses javac to identify the version and not java.
So the command that really shows the version cordova gets when looking for Java is:
javac -version
In my case, even though I had identical versions to what you have in your environment, it turned out my javac was pointing to a newly updated Java (from Ubuntu updates)
To fix it, I used the update-alternatives command and set javac back to my 1.8.0 version as follow:
sudo update-alternatives --config javac

How to configure JDK environment path not JRE?

I have install JDK 8 and my environment path is
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk"
PATH=$PATH:/usr/lib/jvm/java-8-openjdk/bin
Here is my Java version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.18.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
I am getting problem while installing Maven on Ubuntu
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Just run update-alternatives --config java this should gives you the path to the java home.
After this you can set your JAVA_HOME path simply. Just edit your ~/.bashrc and add this line export JAVA_HOME=<path_given_by_the_command above>. After this reload your bashrc.
Once you have installed oracle JDK on your Ubuntu then run below command to set JDK as default
sudo apt install oracle-java8-set-default
This will set environment variable path and you don't need to change config files manually.
Try getting the path using readlink
export JAVA_HOME="$(readlink -f /etc/alternatives/java | sed -e 's/\/jre\/bin\/java$//')"

JAVA_HOME is not defined correctly. ubuntu

When I check maven Version
$ mvn -version
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-8-oracle/bin/java
How to solve it ?
these are my java jdk version.
$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.18.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
Make sure your JAVA_HOME variable is set to the JRE folder, like this:
/usr/lib/jvm/java-8-oracle/jre
To further improve your setup, you can let Java pick the correct version by putting this in your JAVA_HOME (this assumes you used the Oracle installer):
export JAVA_HOME=$(/usr/libexec/java_home)
If this doesn't work for you, make sure permissions are set correctly (Execute permissions on the binaries)

how to delete java 10 ? [duplicate]

How to downgrade Java from 9 to 8 on a macOS Sierra 10.12.6(16G29) . I tried removing the Java plugin and installed Java 8, however the Java and javac version shows 9 in terminal, but In system preferences it is 8.
You don't need to down grade. You can run more than one version of Java on MacOS. You can set the version of your terminal with this command in MacOS.
# List Java versions installed
/usr/libexec/java_home -V
# Java 11
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
# Java 1.8
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
# Java 1.7
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
# Java 1.6
export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)
You can set the default value in the .bashrc, .profile, or .zprofile
This is how I did it. You don't need to delete Java 9 or newer version.
Step 1: Install Java 8
You can download Java 8 from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Step 2: After installation of Java 8. Confirm installation of all versions.Type the following command in your terminal.
/usr/libexec/java_home -V
Step 3: Edit .bash_profile
sudo nano ~/.bash_profile
Step 4: Add 1.8 as default. (Add below line to bash_profile file).
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Now Press CTRL+X to exit the bash. Press 'Y' to save changes.
Step 5: Reload bash_profile
source ~/.bash_profile
Step 6: Confirm current version of Java
java -version
If you have multiple Java versions installed on your Mac, here's a quick way to switch the default version using Terminal. In this example, I am going to switch Java 10 to Java 8.
$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
10.0.1, x86_64: "Java SE 10.0.1" /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
1.8.0_171, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
Then, in your .bash_profile add the following.
# Java 8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
Now if you try java -version again, you should see the version you want.
$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
As it allows to install more than one version of java, I had install many 3 versions unknowingly but it was point to latest version "11.0.2"
I could able to solve this issue with below steps to move to "1.8"
$java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
cd /Library/Java/JavaVirtualMachines
ls
jdk1.8.0_201.jdk jdk1.8.0_202.jdk openjdk-11.0.2.jdk
sudo rm -rf openjdk-11.0.2.jdk
sudo rm -rf jdk1.8.0_201.jdk
ls
jdk1.8.0_202.jdk
java -version
java version "1.8.0_202-ea"
Java(TM) SE Runtime Environment (build 1.8.0_202-ea-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b03, mixed mode)
Old question but just had that problem /dumb jira having problems with java 10/ and didn't find a simple answer here so just gonna leave it:
$ /usr/libexec/java_home -V shows the versions installed and their locations so you can simply remove /Library/Java/JavaVirtualMachines/<the_version_you_want_to_remove>. Voila
The simplest solution might be to install Java 8 in parallel to Java 9 (if not still still existant) and specify the JVM to be used explicitly in eclipse.ini. You can find a description of this setting including a description how to find eclipse.ini on a Mac at Eclipsepedia
FOR MAC USERS only
Change for both JRE and JDK version
Path 1 is the JRE - installation path: /Library/Internet Plug-Ins/
Path 2 is the JDK - installation path: /Library/Java/JavaVirtualMachines
JRE Steps:
Change directory via Terminal to the Path 1.
cd /Library/Internet Plug-Ins/
Remove JavaAppletPlugin.plugin
sudo rm -rf JavaAppletPlugin.plugin
JDK Steps:
Do the Steps under JRE Steps
Change directory via Terminal to the Path 2.
step 1
/Library/Java/JavaVirtualMachines
Take a look at all installations at this folder
step 2
ls // to list all files in folder
Remove any installations in this folder.
step 3
sudo rm -rf /Library/Java/JavaVirtualMachines/yourjdkName.jdk
After uninstalling you are ready to go for a fresh installation. Just download you're version of choice and install it.
best solution for this
As mentioned in the offical Oracle Documentation there are two relevant paths you need to delete in case you wan't to remove a Java installation.
Path 1 is the JRE - installation path: /Library/Internet Plug-Ins/
Path 2 is the JDK - installation path: /Library/Java/JavaVirtualMachines
JRE Steps:
Change directory via Terminal to the Path 1.
cd /Library/Internet Plug-Ins/
Remove JavaAppletPlugin.plugin
sudo rm -rf JavaAppletPlugin.plugin
JDK Steps:
Do the Steps under JRE Steps
Change directory via Terminal to the Path 2.
/Library/Java/JavaVirtualMachines
Take a look at all installations at this folder
ls
Remove any installations in this folder.
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-(...).jdk
After uninstalling you are ready to go for a fresh installation. Just download you're version of choice and install it.
You can remove "JavaAppletPlugin.plugin" found in Spotlight or Finder, then re-install downloaded Java 8.
This will simply solve your problem.

GWAN not recognising Sun Java 7

OS:
Ubuntu 12.04 Desktop
Java installed:
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
Running sudo ./gwan gives following error:-
Please install OpenJDK or SUN Java
.
'report.java': to use Java (*.java) scripts, install 'javac' (sudo apt-get install javac).
'loan.java': to use Java (*.java) scripts, install 'javac' (sudo apt-get install javac).
'argv.java': to use Java (*.java) scripts, install 'javac' (sudo apt-get install javac)..
'hello.mm': to use Objective-C++ (*.mm) scripts, install 'gobjc++' (sudo apt-get install gobjc++)
'all.java': to use Java (*.java) scripts, install 'javac' (sudo apt-get install javac)
Javac, Java both in sys path, both available in terminal
I have not touched any configuration files just went through
http://gwan.com/download
then
tried heading over to
localhost:8080/?hello.java
note: all C files work.
Have not tried openJDK though I would like to stay away from this option.
Try to use the JAVA_HOME environment variable to tell which JVM should be used. The G-WAN site has a dedicated Java FAQs entry for that question.
Reporting the same kind of problems in the past I have been told that the next release will be more JVM-agnostic.

Categories