robben
robben

Reputation: 181

Running maven through command prompt

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.

Upvotes: 2

Views: 2977

Answers (3)

Anshul Sharma
Anshul Sharma

Reputation: 3512

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

Upvotes: 1

Jon Thoms
Jon Thoms

Reputation: 10797

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.

Upvotes: 0

cristianorbs
cristianorbs

Reputation: 720

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.

Upvotes: 0

Related Questions