Friday, 23 September 2016

Maven Error When Executed Using Eclipse - No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

One may see following error for the first time when maven project is tried to be run using POM -

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Json: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Problems is about setting JRE version in eclipse/setting javac in POM.

To fix the eclipse to run Maven test -

1. Go to Installed JREs in following way through Eclipse Menu options
Menu ->Windows->Preferences->Installed JREs.

2. Select/Add Installed JRE

Another Approach -
To fix the POM - Set Maven-compiler-plugin

Reference -
http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.apache.maven.plugins</groupId>
  5. <artifactId>maven-compiler-plugin</artifactId>
  6. <version>3.5.1</version>
  7. <configuration>
  8. <verbose>true</verbose>
  9. <fork>true</fork>
  10. <executable><!-- path-to-javac --></executable>
  11. <compilerVersion>1.3</compilerVersion>
  12. </configuration>
  13. </plugin>
  14. </plugins>
  15. </build>

Some times, in-appropriate testng version causes issue.
For example I got following issue with 6.9.13.6 -

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project Json: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [Help 1]

The complete stack trace was - 
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.apache.maven.surefire.testset.TestSetFailedException: Unknown TestNG version 6.9.13.6
at org.apache.maven.surefire.testng.TestNGExecutor.getConfigurator(TestNGExecutor.java:207)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:72)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:110)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:106)
... 9 more

Solution - 
TestNG version 6.9.9 worked well for me.

No comments:

Post a Comment