Beginning Java Programming: Import Projects to Eclipse IDE

Published on
20,326 Points
6 Endorsements
Last Modified:
Community Pick
Kevin Cross
Father, husband and general problem solver who loves coding SQL, C#, Salesforce Apex or whatever.
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench.


While learning Java can be done with a simple text editor like gedit or notepad, occasionally the use of an Integrated Development Environment (IDE) is desired.  Eclipse is one such IDE that is used by a fair amount of developers given it is open source, providing a free tool, coupled with the fact that it has origins from IBM's commercial package, WebSphere Studio Application Developer, which adds power amplified by the community additions since its inception.

With all that said, the premise of this article is that we have an existing Java project that must now be developed further within Eclipse.  Therefore, to get the most benefit, Eclipse (screen shots and instructions shown from version 3.5.x or "Galileo") should be installed as well as a JDK.  We will also need a simple project to work with, but we will create one shortly.

Simple Project

1. Create a folder in a temporary directory of your choice and name it "TestProject".  
2. Open the TestProject folder and create a sub directory called "src".
3. Open the newly created src directory and create a sub directory called "testpackage".
4. Open the testpackage folder and create a text file named "TestClass.java" with the following content:
package testpackage;

public class TestClass {

Open in new window

Challenge: For those really new to Java programming, give the standard "Hello World" style program a whirl. Add an appropriate main method and the code to print greetings on the standard output. As I said, simple!

Now let's do something productive with this meaningful code base, in need of some minor tweaking, in Eclipse. We will look at the more common methods of using Eclipse for this 'project'.

1. New Project from existing source files.

In short, this method allows you to bring an entire project folder into your workspace in three short steps.  

Typically I use this approach for existing project directories in my physical file system workspace but is not yet present in my Eclipse workbench.

1. Launch Eclipse.

2. Create New Java Project.
Click File | New | Java Project (from Java perspective)
Click File | New | Project, navigate to and choose Java Project.
 Select New Project Type DialogClick Next.

3. Complete New Java Project Dialog.
Click "Create project from existing source" radio button.
 New Project DialogClick browse and navigate to the TestProject directory (you don't need to open, just highlight the folder) then click OK.  

Challenge: explore for yourself having different JRE or project layouts (i.e., what if your Java files were not in a folder called src or even in root of your project folder).

Click Finish and enjoy!

2. Import File System Resources: add source files to a project already in workbench.

This is useful when you have files in a different workspace or other application that you would like to reuse in some fashion in a new project.  If the file existed in your workspace, it is easy enough to copy and paste or refactor | move files or update build path / source folders without having to go through additional processes.

1. Launch Eclipse.

2. Create New Java Project.
Click File | New | Java Project (from Java perspective)
Click File | New | Project, navigate to and choose Java Project.
 Select New Project Type DialogClick Next.

3. Complete New Java Project Dialog.
Type in project name "TestProject".
Click "Create new project in workspace" radio button.
Click Finish.

4. Import File System Resource.
Expand the TestProject in your workbench and click on src folder (highlight it).
Click File | Import... OR Right-Click | Import...
Select File System from the Import dialog.
 Select Import Type DialogClick Next.

5. Complete the Import Dialog.
Click browse (for the From Directory value) and navigate to the src (location of your Java files and packages) under the TestProject directory we created in the Simple Project section (you don't need to open, just highlight the folder) then click OK.
 Import Dialog (File System)Select the src folder (or individual folders or files below this level you would like to import).  We are discussing bringing in an entire project, so the entire folder is most appropriate in most of these cases.

Note: the Into Folder location is set to TestProject/src since we highlighted this source folder before initiating the import process.  This coupled with the create folders options will ensure that your package structure is recreated on import.

Click Finish and enjoy!

3. New Project from existing Ant buildfile.

If you were previously coding by hand, there is a good chance you were building using Ant or having exported this project from another IDE that is Ant-based, you may already have a buildfile that we can utilize to bring our project into Eclipse.  

Additional reasons to use Ant buildfiles would be to allow programmers to share project code despite IDE each has chosen to work in; therefore, this approach may be useful in team environment as well.

Example Ant Buildfile:
(build.xml placed in root of project folder at same level as src directory)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="TestProject">
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.launch"/>
                <exclude name="**/*.java"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <javac destdir="bin">
            <src path="src"/>

Open in new window

For more details on Ant and specifically writing a buildfile, please see Ant's manual on the topic here.  Key for this method is the javac task:
<javac destdir="bin">
    <src path="src"/>

Open in new window

There must be at least one of these for Eclipse to create a project using this file.

For those that already have their buildfile ready to go, let's get to it...

1. Launch Eclipse.

Note: if you like to have your Java projects in one workspace, then you should copy the entire project folder including the Ant build file to your workspace before going through steps below.

2. Create New Project.
Click File | New | Project, navigate to and choose Java Project from Existing Ant Buildfile.
 Select New Project Type DialogClick Next.

3. Complete New Java Project Dialog.
Click browse (for Ant buildfile) and select the above build.xml file, then click OK.
 New Project Dialog (Ant)If you have multiple javac tasks, then select the declaration to use in defining the project.  For the above, you will see '"javac" task found in target "build-project"', which will be auto-selected since it is the only javac task in our simple buildfile.

Challenge: what is the difference between a buildfile linked to in the file system and one that is not?

Click Finish and enjoy!

4. Import Existing Project: add former projects to new workspace.

Last, but not least, we can utilize the import existing projects approach available in Eclipse.

I use this approach a lot when building new machines or switching between repositories of code or re-installing Eclipse but wanting to pick back up a project previously in an older installation or workspace.

In order for it to work, however, the project has to be an existing Eclipse project or at least we need to make Eclipse believe so.  The key is the .project (hidden file on some operating systems) that is in the root of the project folder.

Example .project File:
<?xml version="1.0" encoding="UTF-8"?>

Open in new window

Take the above and save it as .project under TestProject directory.

For different projects, simply change the value of the name tag (i.e., <name>SomeProject</name>) and you can convert other projects to Eclipse projects for this import to work.  Again, this is from Eclipse 3.5.x for Java project, so to ensure you have the correct XML schema I would suggest grabbing the text from a working Eclipse project's .project file and edit as needed.  

Okay, you ready, let's get to it...

1. Launch Eclipse.

2. Import Existing Project.
Click File | Import... OR Right-Click (in Project or Package Explorer Pane) | Import...
Select Existing Projects into Workspace from the Import dialog.
 Select Import Type DialogClick Next.

3. Complete the Import Dialog.
Click browse (for select root directory entry) and choose our TestProject directory, then click OK.
 Import Dialog (Existing)If you had multiple project files (e.g., if you picked a workspace directory), then you can import multiple projects at one time.

Note: if you like to have your Java projects in one workspace, then you should ensure to check "copy projects into workspace" option.

Click Finish and enjoy!

I find this very useful as I said for restore of environment after clean installation, as can store my old workspace as an archive on server and then re-import all my projects at one time.


You should now have a project in your Eclipse workbench that looks like the following :
 Workbench with TestProject
Depicted in the illustration :
Project named "TestProject"
Source folder "src"
Package name "testpackage"  
Class file "TestClass.java"  

Challenge: explore some of the common tasks you may need to do to further make your project ready for development in Eclipse like configuring additional libraries, source folders or references in your build path.


As you can see these methods are very useful, but at the same time straight-forward; therefore, you should be able to get your project up and running with low effort in order to get to what you love: Java!

Happy coding!

Best regards,

Kevin (aka MWVisa1)


Special thanks to EE Member and Page Editor mark_wills for his guidance on the structure of this Article!  

Thanks to him and to you all for taking the time to read this.

If you liked this Article, it helped you solve an issue you were having getting your project started in Eclipse or just because...please remember to vote Yes below to show your support.

Related Resources / References:

Eclipse.org Web-site

Java Development Kit (JDK) Download

The Java Tutorials

Writing a Simple (Ant) Buildfile
(or use manual landing page to get table of contents)

Author:Kevin Cross
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free