No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

后端 未结 30 2199
盖世英雄少女心
盖世英雄少女心 2020-11-22 15:40

I\'m compiling a project in Eclipse using m2eclipse. I set the JDK path in Eclipse like this:

Windows-->preferences-->installed jres--> jdk1.7.xx  p         


        
相关标签:
30条回答
  • 2020-11-22 16:25

    I faced the same issue while trying to build a jar file of my project application using mvn clean install, though the application was working fine while running from Eclipse.

    The issue was, indeed too naive, that I had not set the JAVA_HOME environment variable. All I had to do is set JAVA_HOME environment variable to JDK directory, make sure it is not till "\bin" and without semi-colon ";".

    How I understood it is as:

    The application worked fine in Eclipse as JRE System Library was referring to JRE inside the JDK folder instead of external JRE folder without JDK. [As explained very well in other answers]

    This configuration does not apply to maven command that we run on command prompt. It will still look for JAVA_HOME variable to access the JRE System library and when it is not found it refers to external JRE folder without JDK.

    0 讨论(0)
  • 2020-11-22 16:25

    There is another possible answer to this question, and I may be the only person foolish enough to have stumbled upon this, but I think it's worth adding, since none of the other answers applied as I already had those settings correct.

    When you install a JDK, the installer asks you where you want to install the files. By default, on Windows, this is something like C:\Program Files\Java\jdk1.8.0_74 (or whatever version you are installing).

    It then asks you for a directory to install the JRE to, which by default is something like C:\Program Files\Java\jre1.8.0_74.

    Note that one is jdk1.8.0_74 and the other is jre1.8.0_74

    I was rushing things, and thinking the installer was asking me the same question twice, set both my JDK and JRE install locations to D:\devtools\jdk\jdk1.8.0_74, resulting in the installer overwriting the JDK with the JRE. This resulted in (among other things) a missing javac.exe in my JDK bin, and the same error the OP reported here in all my maven builds.

    0 讨论(0)
  • 2020-11-22 16:25

    There are several answers regarding this question but all are related to right path configuration of JDK, but with JRE only we can solve this problem.

    We just need to make use of deployment assembly to configure the path of packaged war file of the Java EE Project and then re-run the maven-install.

    Steps to make use of deployment assembly:

    1. Right click on the Jave EE project --> click on Properties --> click on Deployment Assembly

    2. Click on Add button --> Click on Archives from the File System --> Click on next --> Click on Add --> Go to the .m2\respository directory and search for the war file generated --> Select war file --> Click on Open button --> Click on Apply --> OK

    3. Right click on the project --> Click on Maven Install under Run As

    This will build your project successfully, without any compiler error.

    Hope this solves the problem without JDK.

    0 讨论(0)
  • 2020-11-22 16:27

    In my case it was solved by doing this:

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

    I copied answer just in case it is deleted for some reason, but the source is here

    0 讨论(0)
  • 2020-11-22 16:27

    If you are running the Maven command from cmd, make sure you set the jdk path before running the command. In my case, I have created a .bat file containing the following:

    set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60
    start cmd.exe /k "cd c:\aem_proj\sis\aau"
    
    0 讨论(0)
  • 2020-11-22 16:28

    I was getting this error when trying to do a maven build from within eclipse.

    For me, the answer was going to Run -> Run Configurations, selecting the Maven Build I was running (from the left panel). Then, I clicked the JRE tab and selected the option Workspace default JRE

    0 讨论(0)
提交回复
热议问题