Running Gradle project via Eclipse errors “system Cannot find System Java Compiler”

自闭症网瘾萝莉.ら 提交于 2019-12-17 16:09:10

问题


When I run Gradle project via Eclipse I get below error.

system Cannot find System Java Compiler.

Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

Could not execute build using Gradle installation 'C:\gradle-1.2-all\gradle-1.2'.

But I have installed JDK 1.7 and set the JAVA_HOME environment variable.


回答1:


Go to File -> Other Settings -> Default Project Structure

Now Set your JDK location




回答2:


In Preference of Eclipse (main menu: Window -> Preferences), select

Gradle -> Arguments -> Java Home, select "Workspace JRE".

Then select one of your jdk in your workspace.

On my laptop it's "jdk1.6.0_45". Yours should be the JDK 1.7 home folder, something like "/usr/lib/jvm/java-7-openjdk-amd64/".




回答3:


You can face this problem even when all your system variables are set and correct. Usually this happens when you work with foreign code from Github etc.

So what you have to do is to check gradle version in your project level build.gradle file, and if it doesn't match to current installed version, update it.

buildscript {
    //other setupps
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0' //update this to your current version
    }
}



回答4:


In Gradle Task View -> build -> right click->Open Gradle Configuration -> JAVA_HOME -> and put the current value of your enviroment, something like C:\Program Files\Java\jdk1.7.0_79

I hope this help you




回答5:


I tried following, but in Eclipse (luna), Run as, "gradle build Gradle build", still failed.

  1. change JAVA_HOME

  2. Preference, Gradle -> Arguments -> Java Home, select "Workspace JRE".

Solution: Go command line, run gradle build as answered by user3754672, then back to Eclipse, all working.




回答6:


It's likely you haven't installed a JDK. Even though you have "jdk1.7", you may have only the runtime environment. You may need to install the "-devel" option for the package, for example, both these would be required:

  • java-1.7.0-openjdk
  • java-1.7.0-openjdk-devel

If you can't find the right package, tell us your distro and the exact name of the jdk1.7 package you have so we can help more.




回答7:


Although you may have a full JDK installed somewhere, and pointed to by JAVA_HOME, I don't think the Eclipse Gradle plugin will use it by default. I ran into the same problem running the the "test" target for the Gradle "quickstart" app in Springsource Groovy/Grails Tool Suite 3.3.0(Gradle IDE 3.3.0.201307040643 plugin).

If you re-run the failed Gradle target from the "External Tools" menu (under the "arrow with a suitcase icon"), adding "--debug" in the "Program Args" under the Arguments tab, it will show you in the console what JVM/JDK it uses. I was able to get around the problem by deselecting "Use Gradle wrapper's default" in the Java Home section of the Arguments tab, and replacing it with an Execution Environment setting that pointed to my 1.7 JDK that I had installed. I'm sure there's a way to have it do this by default, so you don't have to configure each targets run configuration, but this method should fix the immediate problem.




回答8:


I think the wrapped gradle uses the same java as eclipse. Since Eclipse seems to use jre by default you can get the issue mentioned in the question. Try this: Go to your eclipse.ini and add -vm argument like this:

-vm
c:/java/jdk1.8/javaw.exe



回答9:


Issue

Using the Eclipse -> gradle -> select task to execute and error "...cannot find system java compiler."

Solution

Go to the path where your build.gradle path is... and using the cmd manually type gradle build <- this will work.

Done.

Back to Eclipse and execute the gradle task. It will work again!




回答10:


Change your gradle to min: classpath 'com.android.tools.build:gradle:2.0.0'and then Android Studio will ask you to update it. You will make and update of gradle and after that it will work.That is how I fixed it for me.




回答11:


I deleted some old jdk's and encountered the same issue. None of the above outdated solutions worked. Gradle in its infinite wisdom stores the JDK location in C:\Users\User.gradle\gradle.properties. This property is not accessible via the IDE as far as I know.




回答12:


My Eclipse version: Eclipse Java EE IDE for Web Developers. Version: Photon Release (4.8.0)

Right click 'gradle.build' and then choose 'run as' -> 'Run Configurations'. In the left, choose 'gradle.build' under 'Gradle Project'. In the right, you could see something like 'Gradle Tasks', 'Project Settings', 'Java Home' and so on. Choose 'Java Home', you will see there is an input box. Put your JDK path there. (something like: C:\Program Files\Java\jdk-10) And then run.



来源:https://stackoverflow.com/questions/16913397/running-gradle-project-via-eclipse-errors-system-cannot-find-system-java-compil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!