Maven "JAVA_HOME should point to a JDK not a JRE"

21,462

May be java path configuration missing. You can follow this steps:

  1. Create or export JAVA_HOME="JDK directory" . Ex. "C:\Program Files\Java\jdk1.8.0_65"
  2. Create or export Path variable for PATH="JDK Bin DIrectory" . Ex. "C:\Program Files\Java\jdk1.8.0_65\bin"
  3. Run command java -version from your terminal.Check it is correct or not.

Then configure maven. follow these steps : You can try to install maven globaly. you can skip these steps if already configured.just for check run mvn --version command for checking maven is installed correctly.

  1. Download maven from maven download link

  2. Create or export M2_HOME="MAVEN ROOT LOCATION". Ex. : E:\SoftwareRepo\building tools\apache-maven-3.5.2

  3. Create or export MAVEN bin folder location to PATH variable. For example: E:\SoftwareRepo\building tools\apache-maven-3.5.2\bin

  4. Open terminal or cmd and run mvn --version to confirm maven is installed or not.

Share:
21,462

Related videos on Youtube

david
Author by

david

I have a passion for software development. Always trying to keep up with the new technologies.

Updated on January 12, 2021

Comments

  • david
    david over 3 years

    I had the following command working fine with OpenJDK

    mvn clean install
    

    I then uninstalled OpenJDK and installed Oracle JDK 8, and now when I run mvn clean install

    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

    I'm running Linux Mint 19, I did run into a few Stackoverflow questions related to the issue. Most where related to Windows and some that were related to Linux. The Linux ones recommended to run

    sudo update-alternatives --config java

    but in my case I get

    There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-oracle/jre/bin/java Nothing to configure.

    Any idea how I can make mvn clean install work again?

    • david
      david over 5 years
      @ElliottFrisch I had accidentally pasted the wrong thing in my question. I fixed it. mvn clean install says 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
    • Scary Wombat
      Scary Wombat over 5 years
      Java home should be /usr/lib/jvm/java-8-oracle/jdk - check that it exists
    • david
      david over 5 years
      @ScaryWombat I don't see jdk. I have bin lib src.zip COPYRIGHT LICENSE THIRDPARTYLICENSEREADME-JAVAFX.txt include man THIRDPARTYLICENSEREADME.txt javafx-src.zip README.html jre release
    • Henry
      Henry over 5 years
      Do you have a directory /usr/lib/jvm/java-8-oracle/bin that contains among others java and javac? If yes, set JAVA_HOME to /usr/lib/jvm/java-8-oracle.
    • david
      david over 5 years
      @Henry I do, how do I set JAVA_HOME?
    • Scary Wombat
      Scary Wombat over 5 years
      Yes I do not think you have a JDK installed - try again
    • david
      david over 5 years
      I just uninstalled Oracle Java and installed openjdk-11-jdk using apt. I am sure it's installed. But Maven still gives the same error
    • Henry
      Henry over 5 years
      to set an evironment variable in the current shell use something like export JAVA_HOME=/usr/lib/jvm/java-8-oracle. To set it permanently check the conventions of your Linux distribution.