Eclipse workspace projects suddenly have bad build path - eclipse

I generated several Java projects last spring. Today I opened Eclipse back up and selected the workspace I used in the spring but now all the projects have a red X on them. They all list the same problem:
**The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project.**
The build path looks ok (I think). I tried to create a new project as an experiment to see it there are differences. The new project dialog box has **Use default JRE (Currently jre7)** checked and a warning at the bottom:
**The current workspace uses a 1.4 JRE with compiler compliance level 1.7. This is not recommendes and either the JRE or the compiler level should be changed.**
Not sure what changed since last spring but something obviously has. I don't really understand what it is trying to tell me. ?Anybody have any ideas I would greatly appreciate it. Thanks.
Update: I created a new project and compared its buildpath to one of the projects from last spring. In the new project, it has: **JRE System Library [JRE7]**
In the old project that now has the problem I see: **JRE System Library [JAVASE-1.7](unbound)**.
Somehow I think the "unbound" means something bad. Still do not understand how it was ok last spring and now suddenly it isn't.

The "unbound" means that there is no JRE at the path specified in the classpath. My guess is that, since last spring, modifications were made to your java installation(s).
To bind your project back on a JRE, click on your "unbound" JRE and click on the "Edit..." button. In the Edit Library window, select a working JRE (JRE 7 would probably be a good choice in your case), then click on Finish. The "Unbound" message should disappear and your classpath should be okay afterwards.

Related

Setting Eclipse STS to use Java 8 to compile java code of my project

I'm very surprised how hard is it to operate Eclipse - almost everything I try to do ends with SE question.
I have a new project which consists of about two files and some external libraries. This project can by compiled manually by a command line script:
rem List all java files in jar/ directory to text file
dir /s /B jar\*.java > sources.txt
rem make javac compile those files and put the .class files in bin directory
javac -cp %PZCLASSPATH% -d bin #sources.txt
I use java 8 JDK for compiling the project. I am not even dreaming of Eclipse ever building the same way (or building properly at all), but at least I'd like to make it use Java 8 for code validation, as to avoid errors for code incompatible with old java versions:
I looked into project properties and tried to find something to set-up:
As you can see, Java 8 is kinda missing in that menu. In NetBeans, I remember just changing the JDK to desired version. Probably better approach than hardcoded menu.
Also the menu doesn't even seem to have much effect, as I see The import java.util.Arrays cannot be resolved error for import java.util.Arrays; command:
So it's not using even the Java 7 now. Note that other projects work fine in the IDE, but this one has been handcrafted so is problematic.
Is there another way of configuring it?
First thing you need to do is make sure that your workspace has access to a Java 8 JRE.
Go to "window >> Preferences". Then type "JRE" in the searchbox. Select "Installed JREs". If no Java 8 is there. Add one.
Now that Eclipse has a JRE available you can start using it in your projects. You can either set the Java 8 as the 'default JRE' by clicking checkbox in front of it in the same "Installed JREs" prefs dialog, or select it for a specific project (this is really the best as making it the default doesn't guarantee a project will use it, since its only a 'default' used unless a project sets it specifically).
Right click the Project and go to "Properties >> Java Buildpath".
Check the "Libraries" tab shows a "JRE System Library" for Java 8. If it shows a wrong JRE, remove it and add a new one, make sure to select one with the right "Execution Environment" you want to use:
Normally this should be enough. The compiler target / source levels generally automatically follow the JRE version. Though... it is actually possible to override that. This is because JDK 8 is backwards compatible and capable of compiling and running to Java 7, 6 etc. So the compiler source and target levels are independently configurable.
So... its best to check them and make sure you didn't override the compiler settings by accident. You already have screenshot for that setting so I assume you know where to find it (Project >> Properties >> Java >> Compiler). However, unlike shown in your screenshot, I suggest that you don't set it specifically, but rather select the option to make it follow the selected JRE:
Final Note: Manually configuring this is indeed a bit painful. People usually don't do that however. If you use maven, for example, then assuming your pom file specifies all the details of how to compile your code and what JRE it requires, then a tool like M2E will configure Eclipse for you, and all that is left for you to do is the first step from my instructions, to ensure that the needed JRE is available to use. M2E will handle all the other steps automatically).

Why does my eclipse project not have a build path?

What is the advantage with not having a build path in eclipse? Why is that setting default when it's like something you'd never use? It seems eclipse indigo was developed to make software development as obscure as possible. I just checked out a fresh copy of the project I checked in (called dungeonworld) this afternoon from another computer and automatically nothing works, can't compile, can't choose build path, can't add jre, can't add jdk, can't add that to project properties.
Is my eclipse broken? I can't believe this is happening, such an easy thing not feasible.
Nothing above solutions worked for me so i tried below
Right click on project >> properties >> project facets >> click on java
It looks like you did not add Eclipse project metadata files to your source control system, so Eclipse doesn't know what your build path is or whether it is even a java project. You can see that the little folder on your dungeonworld project is missing the little 'j', which means Eclipse doesn't think it's a java project.
Go back to your other computer and look for the following files in your original project root...
.project
.classpath
.settings/*
Make sure all of the end up in your source control system or nothing will work right.
I have same problem, but i have solved
project right click -> properties -> java build path -> src/main/sources
all remove items on "Excluded", and then that item turn the status "(None)"
I tried below steps and it works for me.
Right click on project >> properties >> project facets >> click on java
Eclipse has a build path.
It's stored in a (by default hidden) .classpath file in your project.
You can also access it through the UI in project properties (right click on your project, properties, java build path).
Well, this is probably not your problem, but similar is happening if you are in Eclipse different perspective (for example for Python).
vs.
There where no entrys after right click on my projekt in Eclipse. How to click something, wenn build path entries are missing. So my Eclpise didn't detect my java project. I used following Maven command and after that I cleaned the project too. Now Projekt works as expected. So...
If you are using Maven, try mvn eclipse:eclipse in cmd console in your project directory! Make sure to use the path to your Maven folder for the command.
For example:
cd C:\yourEclipseProject\
C:\yourPathToMaven\apache-maven-2.2.1\bin\mvn eclipse:eclipse
This was helping me. After unsuccessful web research, a coworker told me this tip.
I just had a similar problem and I figured out that I had been choosing General Project instead of Java Project while creating a project. After I chose Java>Project it solved my problem. Maybe it'll solve yours as well.
After choosing that, eclipse automatically included java libraries as well.
It's not a good practice to commit IDE related files into source control. What if someone in team uses different IDE? It might have been only option at a time when OP asked this question.
New versions on eclipse (4.x) takes care of this automatically. Probably by observing what kind of source and build files you have in your project.
Don't know the reason. But this works for me, so posting it.
Right click on project -> 'Properties' -> 'Java Build Path'.

Eclipse JRE Definition not including core classes

I am trying to lnclude an additional JDK (really JRE) to my eclipse project as i need to build against the IBM Java 5 JRE.
When I add the root folder of the jre it appears as if the core java class jars are not being added and only the jars in \lib\ext are being added. That is problem 1.
The next issues is I can't even manually add the jars by adding external jars to the runtime library. The reason being when I hit ok to save off the changes and then hit ok to the preferences dialog. The changes do not truly save. I open up the jre definition dialog again and only the jars in \lib\ext are there again.
Is this an eclipse bug? Is anybody finding similar results?
I'd really like to figure out where these preferences are stored so I can manually edit the file if need be.
As a side note, I have had a similar experience with not being able to save .pmd rule preferences and having to edit them manually in the backend. Though I suspect that bug is on the PMD developers.
Anyway any help on this is greatly appreciated.
Thanks.

Mysterious Eclipse javadoc problem

I had a problem with finding Java docs in Eclipse. I seem to have fixed the problem, but I'm posting this for two reasons: I would like to know why I had the problem in the first place and perhaps my method of fixing it might be useful to someone else having a similar problem.
I created a simple Java project in Eclipse (Helios on Windows 7) and selected the JavaSE-1.6 JRE. Then I created a source file and imported java.util.GregorianCalendar. When I hovered over GregorianCalendar, I was getting the message:
This element has no attached source and the Javadoc could not be found in the attached Javadoc
None of the methods of GregorianCalendar seemed to have any Javadoc, either. Other standard Java classes (even others in java.util, like ArrayList) didn't have this problem; only GregorianCalendar. Everything seemed set up properly in the project settings. The Javadoc location set in the Java Build Path was http://java.sun.com/javase/6/docs/api/.
I managed to restore correct behavior by temporarily switching to JavaSE-1.7 and then back. Evidently something got reset and all is well. While I'm happy that things are now working, I don't like being clueless as to how they got messed up in the first place.
Can anyone provide any insights into this?
I think general support relies on the presence of a src.zip in your JDK directory, which is detected when you autosearch a directory for Java installations. It could be missing. Not sure if online Javadocs are used.
I'm using Eclipse Juno on a Windows 7 64-bit (with a 32-bit JDK) but i think it will also apply to your Eclipse version:
Download JDK docs zip file to your Desktop folder;
Right-click on the file, choose Properties and unblock it;
Move the file to a location of your choice. I normally move it to the JDK folder;
Open Eclipse and go to Window->Preferences->Java->Installed JREs;
Select your JDK installation and press Edit;
Select the rt.jar file and click "Javadoc Location..." button;
Select the "Javadoc in archive" radio button;
Set the archive path by browsing to the JDK docs zip file;
Set the "Path within archive" to "docs/api" (without the quotes).
Enjoy! ;)

Red exclamation mark in Eclipse with mercurial

I have imported a project with Mercurial (hg clone ...).
When opening it with Eclipse, a red exclamation mark appears by the project's name in the Project Explorer, and it cannot be built. Silly messages like "import java.util cannot be resolved" appear, and errors in files are not marked in the Package Explorer.
How can I resolve this?
Check the problem view. By exclamation it is usually means a problem with build path
Check the Build Path of the project by right clicking the project and select Build Path -> Configure Build Path.
One problem I often encountered is different people using different Java SDK and so when the exact SDK is not available in your machine, you need to change to your Java SDK (via JRE System Library -> Alternate JRE). A better way to avoid this problem is to always select the JRE System Library from Workspace default JRE or Execution Environment.
I solved the problem by adding the external .jar file in to my project.
RightClick on the project -> Properties -> Java Build path -> libraries tab -> Add jar
Select your jar file and added it
Thats it the red ! mark gone.
Some times it happens that you have added a jar file earlier but currently not using it. Then after some time you delete the jar file from your system. But since you are not using the library file, so you will not get any error.But then you will see the red exclamation mark for the project. So all you need is to remove the added jar from the Build Path.
Done.....
The Java Runtime Library was defined wrong for the pulled project.
It had to be reset under Project | Properties | Java Build Path | Libraries.
It means there is a problem with the build path in your project. If it is an android project then it mostly means the target value specified in project.properties file cannot be found. This can also be caused because of other kinds of built problems. But it is shown mostly for built problems only. See here for more details. It is about built error decorater seen in eclipse.
An extract from that page:
Build path problems are sometimes easy to miss among other problems in a project. The Package Explorer and Project Explorer views now show a new decorator on Java projects and working sets that contain build path errors:
The concrete errors can be seen in the Problems view, and if you open the view menu and select Group By > Java Problem Type, they all show up in the Build Path category:
I figured out each time i am trying to import a library into my android project, i have a red exclamation mark with both ActionBarSherlock and Facebook libraries
This is how i solved it:
After adding the library into your project "project properties->Android->Librairy->add"
If you are using Eclipse, all you have to do is to clean your project and build all your workspace:
"project -> clean... -> "clean selected project" -> build the entire workspace
For me, the problem was a simple one - the reference project was compiled in 1.5 and my project 1.6. Matching the two solved the issue.
Right-hand-click on the project, select properties, select java compiler.
This is how I solved this problem:- Right-Click to project->properties->Java Build Path->Libraries(tab)->Remove the Jar which is already present there with a Path given along.