Maven Package Compilation Error
Asked Answered
C

11

25

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

Claudetteclaudia answered 5/3, 2013 at 9:39 Comment(9)
in console, what is your javac output ?Alli
Did you run mvn -e package?Supposed
You should read the error messages well: [ERROR] ***No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?*****. I would suggest to check JAVA_HOME and if it's pointing to a JDK and **NOT to JRE.Wickham
@orique: i didnt run mvn -e packageClaudetteclaudia
@Wickham JAVA_HOME is set to JDKClaudetteclaudia
The message says something different in contradiction to your post.Wickham
I faced the very same issue. Please see my answer below!Trivial
on the command line, do mvn -version. Make sure the java installation that's listed after "Java home" is a jdkWanonah
possible duplicate of Eclipse/Maven error: "No compiler is provided in this environment"Quennie
T
49

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\
Trivial answered 19/4, 2013 at 22:6 Comment(7)
Your last answer was lot better than the current version. I came back here for reference and had to go thro the edit histroy to understand the solution. Would appreciate if thats reverted back. ThanksDafodil
@Dafodil Thank you for drawing my attention. I hope it is more complete now! Although you can ommit the step of including the external jar, I have seen it work without it.Trivial
Also for Windows 8 / 32-bit.Colpotomy
I'm on Windows 7. I have followed all the steps, but still no luck ... the same error message about compiler. JAVA_HOME is set and it's pointing to JDK. I'm using 1.6.0_45.Harragan
Can you see the file c:\Java\jdk1.6.xx\lib\tools.jar sitting in your file system? If yes then try to add c:\Java\jdk1.6.xx\lib to your path environment variables.Trivial
Nope, but it's not necessary. I had JDK set in Installed JRE, but it wasn't set in JRE tab in Maven Build Configuration. My mistake... Thank you!Harragan
Perfect!!! Wouldn't have guessed that it was required to change the execution environment in the run configuration as well. +1Flier
Q
14

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

Quennie answered 16/9, 2015 at 20:0 Comment(1)
This was exactly the case for me. Now everything is working fine after I changed to jdk.Chopin
V
3

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

%JAVA_HOME%\lib;

Vagary answered 17/10, 2013 at 19:14 Comment(1)
This was the easiest solution. I simply added C:\Program Files\Java\jdk1.8.0_60\lib to the end of my PATH var and my jenkins build went through.Foretell
U
3

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.

Unbelief answered 16/9, 2015 at 19:22 Comment(0)
R
2

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.

Ronda answered 11/4, 2017 at 11:23 Comment(0)
M
1

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.

Morelock answered 15/8, 2013 at 17:18 Comment(2)
I was getting this error when maven was run as part of a Jenkins job on Windows Server 2008 R2. I had installed Java on a D: drive. After re-installing Java to it's default location on C (and updating JAVA_HOME and the Jenkins configuration), the job compiled without error.Favela
Encountered this again on same Jenkins host but now for maven 3 job. Could build fine from command line. After adding -X to maven config option for the job, I saw maven-resources-plugin had java.home to C:\Program Files\Java\jre7, which was a JRE installed alongside the JDK. I uninstalled the separate JRE and now java.home=C:\Program Files\Java\jdk1.7.0_45\jre and the error is gone.Favela
B
1

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

Broadminded answered 27/1, 2016 at 10:7 Comment(0)
B
0

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).

Bed answered 4/6, 2016 at 15:49 Comment(0)
U
0

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.

Umbilicate answered 22/11, 2017 at 14:15 Comment(1)
While this link may answer the question, link only answers are discouraged on Stack Overflow, you can improve this answer by taking vital parts of the link and putting it into your answer, this makes sure your answer is still an answer if the link gets changed or removed :)Alberthaalberti
P
0

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.

Pudency answered 4/2, 2019 at 20:24 Comment(0)
A
0
  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.

Aeroscope answered 25/11, 2019 at 22:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.