Question
What can I do to resolve the Maven error 'No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?' when trying to run Maven commands?
mvn integration-test -Pamp-to-war
Answer
The error message you're encountering is indicative of Maven running with a Java Runtime Environment (JRE) instead of a Java Development Kit (JDK). JDK is necessary for certain Maven tasks, such as compilation, because it contains the Java compiler (javac). The steps below will guide you through resolving this issue.
sudo apt-get install openjdk-8-jdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-i386
export PATH=$JAVA_HOME/bin:$PATH
# Verify installation
echo $JAVA_HOME
javac -version
Causes
- Maven is using a JRE installation instead of a JDK.
- The JAVA_HOME environment variable is incorrectly set to a JRE path instead of a JDK path.
- The system PATH may prioritize the JRE over the JDK.
Solutions
- Install the Java Development Kit (JDK) if you haven't already. You can install OpenJDK using your package manager: `sudo apt-get install openjdk-8-jdk`.
- Set JAVA_HOME to point to your JDK installation. Use the command: `export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-i386` (adjust the path according to your JDK version and architecture).
- Ensure that your PATH variable includes the JDK's bin directory by running: `export PATH=$JAVA_HOME/bin:$PATH`.
- Verify the settings by running `echo $JAVA_HOME` and `javac -version`, which should now point to the JDK.
Common Mistakes
Mistake: Not installing a JDK.
Solution: Make sure that you have a JDK installed, not just a JRE.
Mistake: Setting JAVA_HOME to a JRE path.
Solution: Update JAVA_HOME to point to your JDK installation.
Mistake: Forgetting to restart the terminal session after making changes.
Solution: Restart your terminal or run `source ~/.bashrc` after updating environment variables.
Helpers
- Maven not compiling
- JRE vs JDK
- Maven error no compiler
- JAVA_HOME not set
- install JDK on Ubuntu