I wanted to start learning java but Eclipse is giving me some trouble.
First of all I'm a beginner with Java with little to no knowledge about it. I want to use 'JavaSe-1.7'. I have no clear reason to use it besides using the latest version. After downloading Eclipse (Eclipse IDE for Java Developers) I created a new Java project and selected 'use an execution eviorment JRE : JavaSE-1.7'. This directly popped the notification saying 'The default compiler compliance level for the current workspace is 1.6. The new project will use a project specific compiler compliance level of 1.7.'. I finished creating the project and started following some tutorials.
However I noticed directly I have 2 errors which dont explain anything or have a source. I ignored it and started typing and tried to import 'java.io.console' however it said 'The import java.io cannot be resolved' and I have no idea what is the cause of it neither how to fix this.
Would like some instructions into the right direction.
Thanks in advance
Check your Eclipse preferences: Java -> Installed JREs. The one that you're using should be marked and it should be a JDK not just a JRE.
Also check your project's build path: Right click on the project -> Properties -> Java Build Path
Check in the "libraries" folder whether the JRE System Library is present and if not add it using "Add library"->"JRE System Library" and then select the correct one (from an installed JDK).
You may not have your JDK/JRE set up correctly.
Check the following:
Did you install a JDK or just the JSE? The JDK is needed to compile .java files to .class files. Without it, you can only run java programs, not develop them. If not, download and install it from Oracle website.
Check in Eclipse, if you have the JRE installed there as well. You just need to specify the path to the installation. You can reach this screen via the "Window->Prefrences" menu. see this screenshot:
The message you receive about project specific compiler compliance level is not a problem, it just means that your workspace is set up to comply to java 1.6 but your project will comply to java 1.7 standards. Also, Java 7 in general is no problem whatsoever.
Paths may differ, especially if you're not running a *nix OS. Just point the location to where you installed your JDK.
Related
I have now a little experience in Java, so I wanted to take the next step to an IDE, so I installed the Eclipse IDE. (If it matters, I am using mac.)
But this does not seem to work right, as soon as I create a new class, the error occurs:
The project was not built due to "release 6 is not found in the
system". Fix the problem, then try refreshing this project and
building it since it may be inconsistent HelloWorld
I already tried to change some of the properties in the class or selecting different settings, right now I use the execution environment JRE: J2SE-1.5.
Thank you for taking your time!
Well it is basically telling you that you don't have the right version of Java JDK installed. THIS page seems to imply the current version of eclipse needs 1.8 - not the 1.6 you're talking about. I am unsure though how you could have specified one that isn't installed. Maybe you only have the JRE (java runtime environment). You will definitely need the JDK (java development kit) because that is what has the java compiler in it.
It's been a long time since I used eclipse but when you created the project you should have been prompted to specify the java version. Now try right clicking on the project and choose Build Path... Configure Build Path. On the Java Compiler tab (left side) you should be able to change the configured Java to whatever you have installed.
I got this error when the selected version under Preferences > Java > Compiler > Compiler compliance level was higher than the selected version under Preferences > Java > JREs > Installed JREs. There was a small (very small) warning at the top of the JREs page warning me that there was an incompatibility with the compiler compliance level.
The options for compiler compliance level includes all versions up to the version that Eclipse itself is using, even if you don't have a specific JDK with that version, so you can get warnings for JDK releases that you definitely don't have.
I updated the compiler compliance level to be the correct version for my project and that got rid of the problem.
When I try to run my program using IntelliJ it says I need a project SDK but when I try to set up a project SDK, it says "The Selected directory is not a valid home for this SDK"
This can happen when a java SDK is deleted, moved, or configured incorrectly.
Go into Project Structure (Ctrl+Alt+Shift+s)
On the left under Project Settings select Project
Now see the Project SDK: - it is likely red if cofigured incorrectly or it might say <No SDK>.
Firstly, just see if there is another SDK of appropriate java version in the drop down list you can use.
If not, you can use Edit button on an existing JDK to modify the JDK home path if it is wrong.
Or just press New... and JDK to set up a JDK that is already installed on your machine (e.g. C:\Program Files\Java\jdk1.8.0_72)
...if you have no JDK on your machine (be aware of the difference between a JRE and a JDK) then you'll obviously need to download and install that first
How do I stop maven from constantly updating my Java System Library from JDK 1.8 back to Java SE 1.8? I have configured the build path and I even set my Java_Home Variable to the JDK path. I have also have updated the build configuration. Can someone please specify how to do this with some specific instructions as I am a novice. I also noticed this keeps changing back as well. FYI I am using Eclipse Mars if that matters.
In Regards to the comments below I have shared the Eclipse M2e Plugin screenshot. Even when selected I am not able to proceed to next. I also have shown what's already installed just in case another plugin is hindering me from using the m2e
You need to understand what an Execution Environment (EE) is in Eclipse. The concept of EE is an abstraction over JREs, allowing projects to be configured without absolute paths to JRE locations. From the wiki page:
Execution environments (EEs) are symbolic representations of JREs. For example, rather than talking about a specific JRE, with a specific name at a specific location on your disk, you can talk about the J2SE-1.4 execution environment. The system can then be configured to use a specific JRE to implement that execution environment.
In general, it's not advisable to configure a project to use "Workspace default" as its JRE System Library, because that makes the project inconsistent when loaded into different workspaces. Think about this: what if the project is being developed targeting Java 7, but I pull it into my workspace which has JDK 8; that could be a big problem. By using an EE, the project is configured such that it doesn't know (or care) where I actually have a matching JRE on my system.
I said all that to set up the answer for you, so you understand what Maven is doing and these instructions are doing. m2e, the Maven integration plugin for Eclipse, is (rightly) setting the project configuration to use an EE instead of "workspace default". From your screen shot I can see that you have both JDK and JRE 1.8 set up in your workspace, so ideally you should remove one (the JRE). Got to Preferences > Java > Installed JREs. There you'll see both the JRE and JDK listed. I suggest removing the JRE*.
Then go into the "Execution Environments" preferences section, select JavaSE-1.8 and make sure that your JDK is checked as the default implementation.
Now when m2e configures your projects to use an EE, that EE will be pointing to the JDK you have installed. And if someone else imports the project, it will point to wherever they have a matching JDK installed.
*By the way, it's perfectly acceptable and normal to have different versions of Java there; I often work on different projects that target different Java versions.
I have Java 8 and I've been trying to use a JAR package that uses JRE 6.
In 'Create a Java Project' I used the 'Use a project specific JRE' and also
created a run configuration but when I try to set the alternate JRE to 6, the 'run' button gets blocked out. Are they not compatible or am I missing a step? I've also tried changing the PATH destination, though I'm not sure if that is even relevant to my problem.
EDIT: I am using a JAR package from an online source that is Java 6 compatible and am trying to integrate it into Eclipse Mars with Java 8 installed.
A few items to check, under Project settings: (most of these can be set workspace-wide as well)
Java Build Path > Libraries. Replace JRE System Library with a jdk6 execution environment or alternate JRE
Java Compiler > JDK compliance. Set to 1.6
System:
Check Installed JREs and Execution environments. Make sure a JRE is linked to the Execution Environment for JavaSE-1.6 (with the checkbox).
Did you try just adding the external JAR to the project? Most (non-executable) JARs that were originally made for older versions of java should still work today.
To add an external JAR: right-click on your project in the package explorer and go to Build Path >> Add External Archives... then select your JAR from there. Be sure to leave the project set up for JRE8.
The reason that your run button is blocked out when you switched to JRE6 was because Eclipse detected that it was not installed and therefore cannot run it as JRE6.
I have Java JDK 1.7.0_07 installed and I made sure that the Java build path in Eclipse is pointing to the right directory in my system. How come my machine complains of not having the 'File' object available? I have made sure i imported java.io.*. What could be wrong?
Just make sure the JRE System Library is part of your build path (see the picture below). Check that the System library is set and if not, click on Add library and select JRE System Library.