user2094311
user2094311

Reputation:

Maven Package Compilation Error

i created a webapp project using maven in eclipse. when i run the command mvn package in command prompt it showing folowing error.

[ERROR] 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
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.310s
[INFO] Finished at: Tue Mar 05 14:32:23 IST 2013
[INFO] Final Memory: 16M/218M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project  Compilation fa
ilure
[ERROR] ***No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?***
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

i tried to change jdk and jre. but not working. still it shows same error

Upvotes: 25

Views: 72979

Answers (11)

Mustafa
Mustafa

Reputation: 97

  1. Check your installation JDK and its path - download link

  2. Check its path on environmental variables - check

  3. Add eclipse windows->preferences->Java->installed JREs->add->standart VM -> JRE home (jdk path exmp:'C:\Program Files\Java\jdk1.8.0_221') then apply.

  4. right click your project -> properties -> select (Libraries -> JRE System libraries) -> edit -> choose workspace default JRE (JDK.1.8.0_221)

  5. Right-click your project -> Maven update clean and install project again.

Upvotes: 0

Michael P Stein
Michael P Stein

Reputation: 1

After creating a second workspace to work in a separate source code branch, I ran into a bizarre situation where I could do a Maven build from the command line in the new workspace, but not in Eclipse. I tried setting the JRE configuration to the JDK as described by others, but still no luck. I finally had to search the entire contents of the new workspace's .metadata directory to find the offending files that refused to be reconfigured. The main culprit was

.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.launching.prefs

It still pointed to the wrong directory despite my configuration change. I did a manual edit to supply the correct JDK name and location. I also edited the files under

.plugins/org.eclipse.debug.core/.launches

These all likewise pointed to the JRE instead of the JDK. Once these edits were made, I could build projects in the second workspace from within Eclipse, not just from the command line.

Upvotes: 0

Vipin Purohit
Vipin Purohit

Reputation: 1229

to set path in below manner

keep jdk's path at first place in path variable, so that other java path will be ignored. compilation error will be resolved.

Upvotes: 0

Sym-Sym
Sym-Sym

Reputation: 3606

In Windows 7 - 64 bit, there is a permissions problem which prevents the installer from unpacking the file C:\Program Files\Java\jdk1.6.xx\lib\tools.jar into your local. This jar file is what maven-compiler-plugin version 3.x uses instead of the usual javac

Solution: Run, as an administrator, the Java JDK installer! And make sure the tools.jar is sitting in the C:\Program Files\Java\jdk1.6.xx\lib\

In case you are using m2e maven integration plugin, you want to see the file is visible to Eclipse via the following steps inside Eclipse:

  • Go to Window -> Preferences -> Java -> installed JREs
  • Select the JDK you are using (C:\Program Files\Java\jdk1.6.xx)
  • Press Edit to see the list of jars including tools.jar, OW you can add it as Add External JAR

Then configure the maven run through these steps:

  • Run->Run configurations->Fill in Name, Base directory and Goals.
  • Then in the same window move to the JRE tab and point to the JDK \jdk1.6.xx\

Upvotes: 49

GauRang Omar
GauRang Omar

Reputation: 871

Go to windows -> Preferences -> Java -> Installed JREs

may be jre is already added enter image description here

click on Add -> Standard VM -> Next -> Directory

and browse for the JDK in my case path was C:\Program Files\Java\jdk1.8.0_111

then Click on finish.

you will see window like this

enter image description here

select JDK -> Apply -> Ok

And You are done.

Upvotes: 2

scout
scout

Reputation: 11

I'm using maven plugin for Eclipse (V3.3) and was struggling with this error for a while. I finally found the solution which is linked to stale java sources: it has nothing to do with JRE or JDK (I use JRE 1.7).

I found on other forums that it is a known problem in maven-compiler-plugin (same result for V3.3 and 3.5.1).

So, I just recompiled manually the stale source(s) and ran again the goal, this time without any problem.

To figure out stale sources, run the goal with option -X (debug) and look for entries beginning with

[DEBUG] Stale source detected:

indicating a java class file (to be recompiled manually...).

Hope this can be useful as the message given by maven compiler made me search in a wrong direction (play with JRE, JDK, JAVA-HOME, etc).

Upvotes: 0

Suyog Talekar
Suyog Talekar

Reputation: 11

Go to preferences>installed JRE>

then click add

select C:\program files\java\

press enter

it will search for other jre's than jdk and then choose what is not selected

Upvotes: 1

kdoteu
kdoteu

Reputation: 1557

Go to your 'Runtime Configuration' and configure your JRE to an JDK.

Select the right JDK for your Runtime

Or as @PawanKumarBaranwal suggested, set your default JDK. But care if you have more than one JRE configured.

Select default JRE

Upvotes: 14

Pawan Baranwal
Pawan Baranwal

Reputation: 202

Try this. Go to Window --> Preferences --> Java --> Installed JREs.

Double click the JRE, which is inside installed JREs.

Give the JDK path (for example, C:\Program Files\Java\jdk1.7.0_80\) in JRE Home, and give JRE name as JDK. Click on Finish and then OK.

For me it worked.

Upvotes: 3

Aldous Hinton
Aldous Hinton

Reputation: 31

What worked for me (32-Bit Windows 7) was to add the following to your path environment variable:

%JAVA_HOME%\lib;

Upvotes: 3

Dietmar May
Dietmar May

Reputation: 11

In my case, the error "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK" was due to the JRE being installed in a different location than its default under the JDK.

Running under 64-bit linux, I have Oracle's 64-bit JDK SE 1.6.0_45 installed at /opt/java. The 32 and 64 bit JRE's were installed at /opt/java/jre32 and /opt/java/jre64, with a jre symlink: (ie. ln -s jre64 jre), sojre ->./jre64(meaning/opt/jdk/jrewas a symlink referencing/opt/jdk/jre64).

Once I renamed jre64 to jre (ie. rm jre ; mv jre64 jre ; ln -s jre jre64), this problem went away; and I was able to build using maven (inside of netbeans).

Maven appears to be looking at the JRE path, saying "jre64 isn't the correct name for a default JRE-inside-of-JDK install, so assume a JDK doesn't exist at ../"), which would prevent it from resolving the location of the JDK lib directory containing tools.jar, etc.

Haven't tested it, but the same thing might happen under Windows if the JRE isn't in the default location (or perhaps isn't in the %JAVA_HOME%\jre directory). If both the JDK and the JRE are installed, Oracle's installer wants to install the JRE at %JAVA_HOME%\jre6, not %JAVA_HOME%\jre. That may be because the \jre directory is needed for the JDK uninstall process; if the JRE has been installed on top of the JDK's JRE in the \jre directory, instead of at \jre6, uninstalling the JDK after the uninstalling the JRE will fail unless the \jre directory is copied, JRE is uninstalled, and the \jre copy is restored to \jre.

Upvotes: 1

Related Questions