Mar 13, 2014

f Comment

Eclipse: How to Make a Project a Java Project?

Amazon I checked out a git project in Eclipse Kepler and its source code is all in Java, but it just does not want to be a Java project. I need to make it a Java project so I get content assist function (i.e. When I control + left mouse click I can see the hyperlink takes me to the relevant source code).

How do I make any project a Java project in Eclipse? How do I make Eclipse recognize a project as a Java project so that I can the Java features when I am managing the project?

Solution

Here's how to make any project a Java project in Eclipse.

Step 1: Modify .project

First back up your original .project which lives at the root folder of the project. Then use the following as the .project file.

Note: If you don't see the file, click on the down arrow in Package Explorer, go to Filters, uncheck .* resources.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
 <name>MultiMediaPlayer</name>
 <comment></comment>
 <projects>
 </projects>
 <buildSpec>
  <buildCommand>
         <name>org.eclipse.jdt.core.javabuilder</name>
         <arguments>
         </arguments>
     </buildCommand>
 </buildSpec>
 <natures>
  <nature>org.eclipse.jdt.core.javanature</nature>
 </natures>
</projectDescription>
Once you are done right click on the project's root folder in Package Explorer and select Properties. You should see Java Build Path. Configure it to point to the JRE library you want. In my case I am using C:\Program Files (x86)\Java\jre7. You may need to go to Window -> Preferences -> Java -> Installed JREs to add and select the default JRE.

Note: My JDK contains the actual source code. I prefer it to the JRE because with the former I'll be able to navigate to the source code of any primitive Java class such as java.lang.String. You can download the JDK from the Java website.

Observe in Package Explorer that you see JRE System Library [jre7] in the root project folder. Also the icon next to the folder name should have a 'J' at the top right corner.

Now Eclipse should treat this project a Java project and allows you to exercise any Java-specific features. One of them is content assist: You should be able to control + mouse click any Java class name and any of its methods and navigate to the right place.

Note: If your problem is not fixed restart the project by going to File -> Restart.


Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael