I do not believe this is a duplicate of any of the previous questions concerning Java in Eclipse.
yesterday my machine updated its java version, and after it did that I opened my Eclipse IDE and found I couldn't build most of my Java projects. The last time I used eclipse everything worked and I had not changed any settings.
I should be using java 1.7_80 (my work projects require this), but now when I build my projects eclipse says it is looking for java 1.8_71- but then eclipse says its using java 1.8_77; all the while my Java compiler settings still says I'm using java 1.7...
The Question: Are there any other places in Eclipse where it sets what version of Java is used?
Note: Java 1.7_80 is still in my PATH System Environment variable; those other newer versions are not and never were. I am using ANT. Below are some images to show my problems and settings.
Check Window->Preferences->Installed JREs, there eclipse uses the checked JRE to compile and run your product per default.
There is also a "Java Runtime Environment" option in your Run configuration.
You can also specify project specific Java Compiler options, rightclick Properties on your project.
Edit: for ant launches, see printscreen below:
Edit2: ok I think for Ant, compiler options are irelevant.
What you can try is storing your ant launch in your project and open it with a text editor and search for invalid java configurations:
open your ant launch
goto Common
change to Shared file
choose your project
Try right clicking on the project and select "Build Path" and "Configure build path". Then select the library and change the library to the desired one. Also to check which version of java is install you can use "java -version" in terminal/ command prompt.
Related
I'm getting this error
Error:java: Fatal Error: Unable to find package java.lang in classpath or bootclasspath
in IntelliJ when I try to build/compile any project. Something that should be stated here is that NetBeans, Eclipse and even the javac command line can compile, build, and execute the same project without errors. This is why I suspect that the problem lies with IntelliJ, all other IDEs work well.
In IntelliJ I already:
Restarted, reinstalled
Invalidate Caches / restarted
Deleted / readded the JDK in Project JDK
Deleted / readded the JDK in Platform Settings
Rebuild / recompile
In Windows I already:
Deleted / Reinstalled Java SDK
Deleted / Readded the JAVA_HOME, PATH and CLASSPATH on System Variables
Tried the above on User Variables
Deleted and reinstalled IntelliJ IDEA
I already seached for issues like this on the Internet, here on Stack Overflow I found:
Question #1 | Question #2 | Question #3 | Question #4 | Question #5
And 30+ sites, and tried every answer...
Here you can see my IntelliJ Project Structure the last time that I tried to build/compile
I was using Java 1.8 when I got this error, after some hours, I installed Java 1.7 and the project worked fine. Maybe IntelliJ doesn't support Java 1.8?
Anyway, it would be great if anyone knew a way to make Java 1.8 work with IntelliJ.
I just spent quite few hours on this and found a solution which might work for you as well. IntelliJ seems to have a bug which expects the JDK to be in a different directory than is specified. I followed these steps:
open intelliJ, click help -> show log in explorer
modify build-log/build-log.xml and change <priority value="info" /> to <priority value="debug" />, you may have to run the editor as an administrator
run the compilation which fails with "Error:java: Fatal Error: Unable to find..."
open build-log/build.log and search for rt.jar, you should find it in a block with a set of other JRE libraries and the directory which points to the file should be wrong
In my case the JDK is included in D:\Development\software\jdk1.8.0_20, while the log points to C:\Users\Vladimir\Development\software\jdk1.8.0_20
I fixed the issue by copying my JRE to the place which is expected in the log. And just like in your case this seems to only happen with JDK 1.8.
The problem comes from IntelliJ bug (existing at least in version 14).
It happens when your JDK directory is under the user profile directory. For example, JDK located in this directory (for Windows):
C:\Users\myuser\jdk1.8.0_20
will be stored in IntelliJ internal configuration (file 'jdk.table.xml') as:
$USER_HOME$\jdk1.8.0_20
But your %USER_PROFILE% environment variable could point at some other (non default) location. Then IntelliJ will look at the wrong directory.
Possible fix:
Install your JDK at different directory, which is outside your profile directory. Like:
C:\Programs\jdk1.8.0_20
Then register this JDK for use in your IntelliJ project settings.
I encountered this on Arch Linux 4.16.13 with IntelliJ 2018.1.4 after importing a Java project using Gradle. I made sure that there is a registered JDK in "Project Settings" -> "Project" but IntelliJ was unable to find the classes from the JDK, java.util.List for example.
The solution was to add a new JDK entry at the same path as the existing JDK (/usr/lib/jvm/java-8-openjdk in my case). This will cause IntelliJ to put the files under jre onto the classpath whereas with the old JDK entry, only the files under lib were on the classpath.
Had the same problem. Simple fix to others in case the other answers are complex.
Go to File -> Project Structure
Under Project SDK, choose new and add another JDK.
The default use in my case was 1.8 that was of build 181. I choose the 1.8.0_192 I had recently downloaded.
After applying, the project loads itself.
When I re-ran the test, it works!
If this problem occurs when importing a project in netbeans then try to create a new project then check the properties of your new created project and match those properties with the project that you imported in my case there was a difference between target of android package version.
From what I understood, debugging for hours, the problem is with the location where the jdk1.8 gets installed(/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home), instead of under System/Library).
So the following has to be done to fix in intellij
1. For an existing project, right click and select module settings, and SDK and add 1.8 as a version.
2. Using a terminal go to ~/Library/Preferences//options/. Remove the old JDK specific lines in jdk.table.xml. Update the default version in project.default.xml
Clean you project in intellij and build. It should use the new jdk and sync.
I am using Eclipse 3.8 for Linux with EGit and am trying to import my Java Git repos from Github. The problem is, they are not recognized as Java projects, and therefore Eclipse does not compile them.
How can I get Eclipse to recognize them as Java projects? Thank you for your answers.
go through this way:
eclipse>right click on project>build path>configure.
here you will see a tab called library,
library>"add library">"jre system library"
you will see as option which jre you want to add. you select execution environment as what ever jre u have installed. thats it.
The problem was that I imported it as a general project. For anyone who gets this problem like I did, never import as a general project on Linux (do it on Windows). Instead, choose to use the project creation wizard. Set the name and everything should go by smoothly.
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.
Go to File -> Other Settings -> Default Project Structure
Now Set your JDK location
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/".
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
}
}
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
I tried following, but in Eclipse (luna), Run as, "gradle build Gradle build", still failed.
change JAVA_HOME
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.
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.
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.
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
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!
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.
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.
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.
I reinstall my Eclipse environment every year when the new version is released. The most recent release - Juno - however, does not work as expected.
Currently, when I try running demos from Oracle, for example, it asks me to select an Ant file to run before compiling. After creating a blank Ant file to bypass the requirement (which I thought was rather dumb, since I don't think TDD is something that should be forced on people), it still refused to run, saying the "Selection could not be launched."
I understand that Juno is an update from the 3.x track to the 4.x track, but this seems a little ridiculous to me. What can or should I do so I can get Eclipse back up and running again?
Just to clarify:
All files in question are on my Eclipse workspace path
I don't do much in the way of Java development, though I know I'll need to do so soon. Hence, my unfamiliarity with the most recent version of Eclipse.
I would like to run my files & projects without Ant files. I know it has something to do with Run configs, but I don't know how to change them.
Here's what I did to run the demo from Eclipse Juno:
Downloaded the project from http://docs.oracle.com/javase/tutorial/uiswing/examples/zipfiles/components-FrameDemoProject.zip (if this is not the correct demo, then please provide the link you're using)
Unzipped it to my projects directory (not my workspace), so that you have:
PROJECTS_DIR/components-FrameDemoProject/src
PROJECTS_DIR/components-FrameDemoProject/nbproject
PROJECTS_DIR/components-FrameDemoProject/build.xml
From Eclipse, File > New > Java Project
List item Uncheck Use default location and navigate to <PROJECTS_DIR>/components-FrameDemoProject
Hit Finish
Drill down to src/components/FrameDemo.java
Right-click on FrameDemo.java and select Run As > Java Application
Let me know if any of these steps give you trouble.
Take a look at you project properties and select the Builders entry. Do you see an Ant Builder entry? Try to select or create a Java Builder entry instead.
I just created a new Java Project in Juno and added the FrameDemo.java source. In my case, the Java Builder was selected as the default for this new project.
I have an existing project that uses #Override on methods that override interface methods, rather than superclass methods. I cannot alter this in code, but I would like Eclpse to stop complaining about the annotation, as I can still build with Maven.
How would I go about disabling this error?
Note: Due to project requirements, I need to compile for Java 1.5.
Using the #Override annotation on methods that implement those declared by an interface is only valid from Java 6 onward. It's an error in Java 5.
Make sure that your IDE projects are setup to use a Java 6 JRE, and that the "source compatibility" is set to 1.6 or greater:
Open the Window > Preferences dialog
Browse to Java > Compiler.
There, set the "Compiler compliance level" to 1.6.
Remember that Eclipse can override these global settings for a specific project, so check those too.
Update:
The error under Java 5 isn't just with Eclipse; using javac directly from the command line will give you the same error. It is not valid Java 5 source code.
However, you can specify the -target 1.5 option to JDK 6's javac, which will produce a Java 5 version class file from the Java 6 source code.
Do as follows:
Project -> Properties -> java compiler ->
Enable project specific settings - 'yes'
Compiler compliance - 1.6
generated class files and source compatibility - 1.5
Check also if the project has facet. The java version may be overriden there.
Project specific settings may be enabled. Select your project Project > Properties > Java Compiler, uncheck the Enable project specific settings or change Jdk 1.6 and above not forgetting the corresponding JRE.
Incase it does not work, remove your project from eclipse, delete .settings folders, .project, .classpath files. clean and build the project, import it back into eclipse and then reset your Java compiler. Clean and build your projectand eclipse. It worked for me
You could change the compiler settings to accept Java 6 syntax but generate Java 5 output (as I remember). And set the "Generated class files compatibility" a bit lower if needed by your runtime.
Update: I checked Eclipse, but it complains if I set source compatibility to 1.6 and class compatibility to 1.5. If 1.6 is not allowed I usually manually comment out the offending #Override annotations in the source (which doesn't help your case).
Update2:
If you do only manual build, you could write a small program which copies the original project into a new one, strips #Override annotations from the java sources and you just hit Clean project in Eclipse.
You can also try Retroweaver to create the Java5 version from Java6 classes.
Use Eclipse to search and replace (remove) all instances of "#Override". Then add back the non-interface overrides using "Clean Up".
Steps:
Select the projects or folders containing your source files.
Go to "Search > Search..." (Ctrl-H) to bring up the Search dialog.
Go to the "File Search" tab.
Enter "#Override" in "Containing text" and "*.java" in "File name patterns". Click "Replace...", then "OK", to remove all instances of "#Override".
Go to "Window > Preferences > Java > Code Style > Clean Up" and create a new profile.
Edit the profile, and uncheck everything except "Missing Code > Add missing Annotations > #Override". Make sure "Implementations of interface methods" is unchecked.
Select the projects or folders containing your source files.
Select "Source > Clean Up..." (Alt+Shift+s, then u), then "Finish" to add back the non-interface overrides.
I understood your problem, change your jdk from your jdk to greaterthan 1.5
By configuring that the IDE projects are setup to use a Java 6 JRE or above sometimes does not remove the eclipse error. For me a restart of the Eclipe IDE helped.
Even after changing the compiler compliance setting to 1.6 or 1.7 from
windows tab, then prefernces, then java, then compiler and setting the
compiler compliance, I was still having this issue. The idea is that we
need to go the the project folder, right click, Java and set compiler
compliance to 1.6 or higer. This worked for me.