64

I've never worked with Maven before and I am following the instructions here. When I run the command

mvn integration-test -Pamp-to-war

It initially downloaded a whole bunch of dependencies, and in the end it showed,

COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error

I am on ubuntu 13.04.

If there's anything you want me to tell you, let me know. Thanks.

EDIT

When I do echo $JAVA_HOME I get /usr/lib/jvm/java-7-openjdk-i386/

When I do mvn -version

I get,

Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-i386/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.8.0-26-generic", arch: "i386", family: "unix"

Also, I found out this problem faced by someone else. But I am not sure how to go about the solution that is specified?

Further edits.

kraken@kraken-Inspiron-1545:/usr/lib/jvm/java-7-openjdk-i386$ ls -l
total 12
drwxr-xr-x 2 root root 4096 Sep  9 10:44 bin
lrwxrwxrwx 1 root root   41 Jul  4  2013 docs -> ../../../share/doc/openjdk-7-jre-    headless
drwxr-xr-x 5 root root 4096 Oct 13  2013 jre
drwxr-xr-x 4 root root 4096 Oct 13  2013 man
Community
  • 1
  • 1
Kraken
  • 20,468
  • 32
  • 90
  • 145
  • 2
    Do you have JRE instead of JDK installed? – Zavior Oct 11 '14 at 11:06
  • I have jdk. When I do `echo $JAVA_HOME` it outputs, /usr/lib/jvm/java-7-openjdk-i386/ – Kraken Oct 11 '14 at 11:07
  • 2
    `Java home: /usr/lib/jvm/java-7-openjdk-i386/jre` ends with jre, starts with jdk, hmm :P – Zavior Oct 11 '14 at 11:10
  • If you do `which javac`, what do you get? – Zavior Oct 11 '14 at 11:11
  • @Zavior I've attached a link to the question, that details it. But I am not sure what is the solution that is prescribed there. – Kraken Oct 11 '14 at 11:11
  • @Zavior /usr/bin/javac – Kraken Oct 11 '14 at 11:11
  • possible duplicate of [Maven Package Compilation Error](http://stackoverflow.com/questions/15220392/maven-package-compilation-error) – mlt Aug 17 '15 at 18:55
  • Does this answer your question? [No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?](https://stackoverflow.com/questions/19655184/no-compiler-is-provided-in-this-environment-perhaps-you-are-running-on-a-jre-ra) – hestellezg Mar 26 '20 at 18:06
  • @estellezg The question you link focusses on a problem with Maven within Eclipse, this question is different. – Mark Rotteveel Mar 27 '20 at 10:21

21 Answers21

156

I've been facing the same issue with java 8 (ubuntu 16.04), trying to compile using mvn command line.

I verified my $JAVA_HOME, java -version and mvn -version. Everything seems to be okay pointing to /usr/lib/jvm/java-8-openjdk-amd64.

It appears that java-8-openjdk-amd64 is not completly installed by default and only contains the JRE (despite its name "jdk").

Re-installing the JDK did the trick.

sudo apt-get install openjdk-8-jdk

Then some new files and new folders are added to /usr/lib/jvm/java-8-openjdk-amd64 and mvn is able to compile again.

ced
  • 1,749
  • 2
  • 9
  • 8
43

Apparently, it requires tools.jar file inside the lib folder of my $JAVA_HOME. I did not have the lib folder, so I reinstalled my jdk using command

apt-get install openjdk-7-jdk openjdk-7-doc openjdk-7-jre-lib

Also, this link may help some people.

Kraken
  • 20,468
  • 32
  • 90
  • 145
21

This is because of running jre rather than jdk, to install jdk follow below steps

Installing java 8 in amazon linux/redhat

--> yum search java | grep openjdk

--> yum install java-1.8.0-openjdk-headless.x86_64

--> yum install java-1.8.0-openjdk-devel.x86_64

--> update-alternatives --config java #pick java 1.8 and press 1

--> update-alternatives --config javac #pick java 1.8 and press 2

Thank You

sachin_ur
  • 1,426
  • 12
  • 23
  • Yeah, Only JRE was installed in my case as well. We have to install JDK as well. – Aswin Prasad May 20 '20 at 00:29
  • On RHEL 7.5 I installed java-1.8.0-openjdk, but this does not include the JAVAC compiler, so based on your information I additionally installed java-1.8.0-openjdk-devel.x86_64 and now I have the JAVAC compiler. If it is a JRE it should be labeled as such. This is utter nonsense. java-1.8.0-openjdk is not a JDK. Should be called java-1.8.0-openjdk-jre – barrypicker Feb 21 '21 at 18:36
7

Problem statement = No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Solution

Please set the Environment variable like below to solve the issue

Variable name : JAVA_HOME

Variable Value : C:\Program Files\Java\jdk1.8.0_202

Variable name : M2_HOME

Variable Value : C:\Program Files\apache-maven-3.6.0

Moreover, Add Java and maven path in "System Variables" like below:

  1. C:\Program Files\Java\jdk1.8.0_202\bin
  2. C:\Program Files\apache-maven-3.6.0\bin
Community
  • 1
  • 1
Navdeep Ghotra
  • 161
  • 2
  • 3
6

For me, it worked like following. Please look at JAVA_HOME environment variable, whether it is pointing to JRE or JDK.? If it pointed to JRE, you will face "Perhaps you are running on a JRE rather than a JDK" issue. if so change the path to JDK.

Modifying like this, it worked for me.

JAVA_HOME C:\Program Files\Java\jdk1.8.0_31

sks
  • 137
  • 1
  • 7
3

Just adding more details on where to setup. Main reason would be the JAVA_HOME setup in the environment variable should be pointing to correct JDK location.

  1. Check System -> Advance System Settings
  2. Click on Environment variable
  3. Add variable JAVA_HOME -> "C:\Program Files\Java\jdk1.8.0_141;"
  4. Edit "path" -> append %JAVA_HOME%; to the existing text.
Barani r
  • 1,403
  • 1
  • 16
  • 20
2

Add this configurations in pom.xml

<project ...>
    ...
    <build>
        ...
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <fork>true</fork>
                    <executable>C:\Program Files\Java\jdk1.7.0_79\bin\javac</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>
AnuradhaS
  • 191
  • 1
  • 8
2

Check if /usr/bin has 'javac'. If not you have installed JRE & have to install jdk dev version like "java-1.8.0-openjdk-devel.x86_64"

Raja Rajan
  • 61
  • 6
2

I was facing the same issue. I needed to place the JDK before the JRE in PATH in order to resolve.

MikeF
  • 499
  • 6
  • 16
2

i am using centos and getting same error when run mvn command with goal, install. After some googling i have found the solution to run following command.

sudo yum install java-1.8.0-openjdk-devel

Sheikh Abdul Wahid
  • 1,952
  • 1
  • 19
  • 23
2

Here's my automatic solution...

This will follow your javac executable's symlink (setup by yum and/or alternatives --config java) backwards to find the JAVA_HOME. (Toss this in your in your /etc/profile):

export JAVA_HOME=$(readlink -f /usr/bin/javac | sed 's:/bin/javac$::')

If you wanted a stable path (refreshed on boot) launch something like this:

export JAVA_HOME=$(readlink -f /usr/bin/javac | sed 's:/bin/javac$::')
ln -sfn "${JAVA_HOME}" /usr/lib/jvm/jdk-current

I'm kinda shocked the latter still isn't baked into alternatives.

Ryan
  • 901
  • 8
  • 22
1

This is how i fixed my problem

right clik on the project > properties > Java Compiler (select the one you are using)

it was 1.5 for me but i have 1.8 installed. so i changed it to 1.8.. and voilla it worked!.

Mack
  • 147
  • 1
  • 2
1

I had the same issue after installing the java-1.8.0-openjdk package on an AWS Linux AMI. The incorrect assumption I made, was that because the file ended in openjdk it would be the jdk version. This is not the case.

The openjdk install page explains everything clearly.

The java-1.8.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.8.0-openjdk-devel package.

If you've already installed the java-1.8.0-openjdk package, just leave it and the JAVA_HOME value if it's working for the JRE and install the java-1.8.0-openjdk-devel package using yum install java-1.8.0-openjdk-devel -y.

Paul.M
  • 11
  • 1
0

I had the same error and I was missing the User variable: JAVA_HOME and the value for the SDK - "C:\Program Files\Java\jdk-9.0.1" in my case

assaf.gov
  • 357
  • 2
  • 12
0

I faced the issue even though JAVA_HOME was pointing to JDK. It took time to figure out why it was throwing the exception.

The issue was I set JAVA_HOME as admin user on my window machine. You need to add JAVA_HOME environment variable pointing to right JDK to your user profile environment variable settings.

Arnav Rao
  • 5,423
  • 1
  • 29
  • 29
0

For solving my issue on Linux don't have a JDK, I just download the JDK and upload to the Linux server, and type: tar xvf jdk-8u45-linux-x64.tar.gz

Hailin Tan
  • 625
  • 6
  • 7
0

I was facing the same issue in eclipse maven project, all i did was
right click on the project
maven --> update project
or just press ALT+ F5

Abhishek D K
  • 1,272
  • 9
  • 21
0

If the above solutions doesn't work then try to place java path before maven in path of environment variable. It worked for me.

%JAVA_HOME%\bin

C:\Program Files\apache-maven-3.6.1-bin\apache-maven-3.6.1\bin

Lokesh Soni
  • 39
  • 1
  • 8
0

In Installed JREs path see if there is an entry pointing to your JDK path or not. If not, click on Edit button and put the path you configured your JAVA_HOME environment:

Eclipse Path: Window → Preferences → Java → Installed JREs
Bharat Mane
  • 266
  • 2
  • 10
  • 20
0

I was getting below error in Maven project in Eclipse

Error: [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

I solved it by following the below solution

Solution: Eclipse->Project->Right click->Build Path->Configure Build Path->Add jdk path(Eg: C:\Program Files\Java\jdk1.8.0_45)

Note: Earlier Build path in eclipse project was pointing to jre path

And also add jdk path in Environment Variable in Advanced system settings

Variable Name: JAVA_HOME

Variable Value: C:\Program Files\Java\jdk1.8.0_45

And also make sure in eclipse below pointing is (jdk path-> C:\Program Files\Java\jdk1.8.0_45 )

Windows -> Preferneces -> Java -> Installed JRE's

Yoshita Mahajan
  • 167
  • 1
  • 6
-1

Right click on your project folder (Maven one), select properties and from the properties window, again select Java Compiler and see what is selected against compiler compliance level and make sure that it is the same version as your jre. In my case I had 1.8 but 1.5 was selected against compiler compliance level. After selecting 1.8 the build was successful without this error.

Qaddaffi
  • 67
  • 2
  • 9