1

Maven configuration failed this line just ruined my Friday night and still i am unable to solve it. Well,I am a big fan of visual studio code so i just decided to switch on vscode to eclipse for java development. but this is not the problem,Problem raise when i just try to add an external java library.I am unable to use it and i just get an error something like Class-not-Found or so on.

Well,this is my project structure in vscode

vscode-project-structure

   [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project in.blackpaper.topdf: Compilation failure

This is error message which i get while install mvn plugin.

 mvn clean install

[DEBUG] incrementalBuildHelper#beforeRebuildExecution
[INFO] Compiling 1 source file to E:\Documents\Java\in.blackpaper.topdf\target\classes
[DEBUG] incrementalBuildHelper#afterRebuildExecution
[INFO] -------------------------------------------------------------
[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: 3.086 s
[INFO] Finished at: 2018-04-17T11:23:29+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project in.blackpaper.topdf: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR]
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project in.blackpaper.topdf: Compilation failure
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source)
    at java.lang.reflect.Method.invoke (Unknown Source)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1161)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:168)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source)
    at java.lang.reflect.Method.invoke (Unknown Source)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[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

Well,i also try to solve my problem with vscode developers but still i can't solve it. This is the issue i raised in vscode-github

vscode-java/issue#509

Well,my problem is different from all the previously asked questions about maven-plugins and I tried all available solution but unable to get the point.

Thanks in advance.

Nitin
  • 1,280
  • 1
  • 13
  • 17

2 Answers2

1

The Java installation you're using is not a Java Development Kit (you can understand the difference by looking at this question).

To solve your problem, download and install the JDK (such as from here, or from here, depending on the version you prefer), if you haven't installed it already. After installing and/or extracting (if you're on linix, better done in an init script):

export JAVA_HOME=<path_to_the_extracted_jdk_directory>

On Windows, create an environment variable named JAVA_HOME, with a value set to the full path to the installation directory.

To verify that Maven picks up the correct Java installation, you can try

mvn -version

The output includes a line for the Java installation Maven is seeing, such as:

...
Maven home: [path to maven]
Java version: 1.8.0_152, vendor: Oracle Corporation
Java home: /home/user/jdk/jdk1.8.0_152/jre
...

ernest_k
  • 44,416
  • 5
  • 53
  • 99
  • I have already download both of them.but still it is not working – Nitin Apr 17 '18 at 07:12
  • @NitinKhanna Whichever version is correct for your code is fine. Just make sure that when you run `mvn -version` on the terminal where you will run the build, it outputs a Java home value that points to your JDK installation dir, and it should work. Would recommend you put that `export JAVA_HOME=` in your `.bashrc` file, then try it on a new shell session. – ernest_k Apr 17 '18 at 07:16
  • Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T01:19:05+05:30) Maven home: C:\Program Files\Apache\apache-maven-3.5.3-bin\apache-maven-3.5.3\bin\.. Java version: 9.0.4, vendor: Oracle Corporation Java home: C:\Program Files\Java\jre-9.0.4 Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows" – Nitin Apr 17 '18 at 07:18
  • This is the output of mvn -verison – Nitin Apr 17 '18 at 07:19
  • 1
    @NitinKhanna That's where your problem is. `C:\Program Files\Java\jre-9.0.4` is a *JRE* installation, not a *JDK* installation. If you had a JDK installation, the directory in path would be **jdk-9.0.4**, not *jre-9.0.4*. – ernest_k Apr 17 '18 at 07:21
  • how can i change this with jdk? – Nitin Apr 17 '18 at 07:22
  • You can download jdk 9.0.4 from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-3848520.html. I suppose just installing it fully on Windows should solve the problem. Otherwise you can see its jdk-9.0.4 directory and change the value of the environment variable JAVA_HOME, as pointed out in the answer. – ernest_k Apr 17 '18 at 07:24
  • I have already downloaded both of them and also set the path in the environment variable. Here the are in the list https://imgur.com/a/wCWn1 – Nitin Apr 17 '18 at 07:30
  • What you've shown is the `PATH` variable (which dictates what `java` command resolves to). But what you need to change is the `JAVA_HOME` variable (which maven uses to find what java installation to use). – ernest_k Apr 17 '18 at 07:33
  • That's a different error now. Add a source/target version to your pom, like: ` org.apache.maven.plugins maven-compiler-plugin 3.1 1.8 1.8 UTF-8 true ` – ernest_k Apr 17 '18 at 07:44
0

Please check the terminal, the process holds the lock. So the application files are still used by somewhere. So first we need to stop the process, then start your task it will work.

Kona Suresh
  • 1,836
  • 1
  • 15
  • 25