Managing Files and Projects

Deleting a Class

Now that you know how to create a project and a Java class, you'll need to know how to delete them. To remove a class file from a project, right click on it in the package explorer and select "Delete". A dialog box asking you to confirm will appear. Selecting yes will delete the Java file.

Deleting a Project

To delete a project right click on the project in the package viewer.  Again, select "Delete" from the context menu.  To delete your project select the option "Also delete contents under ...:." and select "Yes".

Importing Files

File System Import

The contents of a Java project are defined by the contents of the folder in your filesystem in which the project is stored. What happens if you want to grab a Java file from some other location and make it part of your current project? This process is called importing and can be done simply with Eclipse: simply right click on the Project in the package explorer and select "Import". This will bring up an Import window that has a couple of options to choose. The two relevant ones are "File System" and "Archive File". If you choose "File System", you can import any Java file from anywhere else on your local file system (i.e., your computer). So you could use this option to pull in a Java file from a folder other than the one you're using for your current Java project. This can be accomplished by first selecting the folder from which you want to import the Java files by either filling in the edit box at the top of the Import window or by selecting it with the "Browse" button. After doing so, you'll see the directory appear in the window on the left. Next to the folder name you'll see a square box that you can check and uncheck. Checking the box means "import everything in that directory". When you click on the directory name, the right window will display all of the files in that directory. Each file will have a similiar checkbox. Each file that is checked will be imported into your project.  Importing files into your project will cause copies to be created of the files you're importing. Thus, once your import a file, a copy of that file will be created and put in your project's directory. Changing the file you've imported will not change the original source file, and vice versa. Deleting a file you've imported from your project will not delete the original file.

Zip (jar) File Import

If you want to import a jar file, you'll want to select your project, right click and choose "Import", but instead choose "Archive file". The options here are very similiar to when importing from the file system, since an archive file is really a miniature file system stored in a single file. After you choose the Jar file you want to import from, you'll see a directory structure with checkboxes that behaves just like when importing from the file system. Check the folders or individual files you want to import and select "Finish." Again, copies of the contents of the Jar file are made, so you can safely manipulate the files and delete them without affecting the source Jar file.

Exporting Files

This time, we're going to be creating a copy of our project somewhere else. Right click on the project and select "Export". You'll see a list of options similar to the list for importing files, and again the relevant options are "File System" and "JAR file". This time, the left and right windows show you the contents of your current project. Checking and unchecking items here selects which files in your project you want to export. If you choose "File System", you simply specify the folder where you want to copy your project files and hit "Finish".

Creating a Jar File

Creating a JAR file is slightly more complicated. JAR files can contain either compiled code, source code, or both. By default, Eclipse assumes you're exporting compiled code, so it only lists .class files and other files required by the compiled code. To change this, modify the checkboxes right below the folder/file windows so that "Export generated class files and resources" is unchecked and "Export java source files and resources" is checked. If you are submitting a project via a JAR file and you forget to do this, you will not provide your .java files.  Make sure you export your Java source files if what you want to provide is your source code.  Once that is straightened out, choose a location for your JAR file and then hit "Finish". You can test whether or not your JAR file worked by creating a new Project and importing your JAR file into that new project as described above. If the new project you created looks just like your original project, chances are your export worked correctly.

Renaming Projects, Classes, Files and Variables

To change the name of a project, class, file, variable or method highlight the item, right-click and select Rename or RefractorRename.  You will then be prompted to enter a new name.

Searching in a Java File

If you are editing a Java file and you want to locate a specific phrase somewhere in your code, you can use Eclipse's search tool. Eclipse has a more advanced searching mechanism than most Windows applications. Select Search Search. This will bring up the search window, which has a series of tabs. These searching utilities makes it easy to quickly locate anything in your project, so experiment with the search tool -- it can save you a lot of time later.