2

I am running my maven build through my command prompt where I set the M2_HOME variable in my system variables. However, when I run a mvn compile in my command prompt I get the following error:

no compiler is provided in this environment. perhaps you are running on a jre rather than a jdk

but when I run the goal mvn compile in my eclipse GUI it works fine.


When I added this to my pom.xml it was able to compile in my command prompt but I need it to work without have to place that in my pom.

<plugin>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>3.1</version>
     <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <executable>C:\programfi\Java\jdk1.8.0_73\bin\javac.exe</executable>
    </configuration>
</plugin>

This is NOT a duplicate question since other questions similar to this is asking for the eclipse GUI, where I am asking for command prompt.

robben
  • 181
  • 3
  • 13
  • What do you get when you type the command `javac` in the command prompt? Make sure that the JDK `bin` directory is in your `PATH`. – Jesper Apr 27 '17 at 18:37
  • @Jesper when I run java -version in my command prompt, it spits out the version so I am assuming it is set correctly. – robben Apr 27 '17 at 18:39
  • 1
    But what about `javac` (the Java compiler), not `java`? – Jesper Apr 27 '17 at 18:40
  • oh, when i use javac it complains. K going to try to set that as my path variable and see if that works – robben Apr 27 '17 at 18:41
  • 1
    Ya, try setting JAVA_HOME and PATH variables correctly. See third answer for this question: http://stackoverflow.com/questions/2619584/how-to-set-java-home-on-windows-7 – entpnerd Apr 27 '17 at 18:43
  • Cool. btw, did setting JAVA_HOME and PATH solve the problem? – entpnerd Apr 27 '17 at 18:57
  • @entpnerd Unfortunately, I won't be able to know until tmw because I need admin credentials to change system variables on my machine. And all the admins left for the day. I will answer back once I have checked and I will accept your answer if you want to add it below. – robben Apr 27 '17 at 19:00
  • @robben I'm pretty sure that you can try this before tomorrow. Try temporarily setting the environment variables in your command shell like this answer suggests. http://stackoverflow.com/a/29413794/4851565 – entpnerd Apr 27 '17 at 19:13

3 Answers3

1

set your jdk path and also set maven path into .bash_aliases file(hidden file) in home directory :-

export JAVA_HOME=/home/hadoop/install/jdk1.8.0_92
export PATH=$JAVA_HOME/bin:$PATH


export MAVEN_HOME=/home/hadoop/install/apache-maven-3.3.9
export M2_HOME=/home/hadoop/install/apache-maven-3.3.9

Additional details for *nix systems and Windows systems has been published by Oracle

Freiheit
  • 8,408
  • 6
  • 59
  • 101
Anshul Sharma
  • 3,432
  • 1
  • 12
  • 17
  • 1
    This will most likely not help, because robben seems to be using Windows and these instructions are for Linux. – Jesper Apr 27 '17 at 18:38
0

You should add Java to your environment variables. Try hitting Windows, search for environment variables and again click the button

Environment Variables...

Then change or create the Variable named: JAVA_HOME, pointing to your Java installation, as you mentioned: C:\programfi\Java\jdk1.8.0_73

Make sure you MAVEN_HOME is correct too.

Then click OK, close the command prompt that is opened and open a new one. Try execution mvn -v and check it the Java version is the one you indicated. If it is, it probably will work on CLI and not just on Eclipse.

It's also worth mentioning that Eclipse not always points to the same JDK and Maven from your system. You should make sure that your command line interface and your Eclipse are using the same tools.

cristianorbs
  • 670
  • 3
  • 9
  • 16
0

Try setting up your JAVA_HOME environment variable to point to the JDK you referenced in your question. This is a good answer on how to do this. Note that the JAVA_HOME environment variable shouldn't contain the \bin directory, itself. Additionally, to get javac to run correctly on the command line, you need to add JAVA_HOME\bin to your PATH environment variable as per this answer.

Community
  • 1
  • 1
entpnerd
  • 10,049
  • 8
  • 47
  • 68