Eclipse settings you must know

Eclipse is one of the most popular IDE for java development. Some of the settings are “hidden” and take time for you to find out. Here I list some eclipse java settings that will help you save time.

Common eclipse settings are:

1. Open the Exiting Projects
2. Remove the red mark on Project in Package Explorer
3. Change System Library
4. Run JUnit
5. Import External JARs
6. Turn on Autosave
7. Run with Arguments
8. Increase JVM heap size to run program
9. Find the Command Line to Run the Program
10. Add Tomcat Server


1. Open the Exiting Projects

To open the java files in a folder:

Go to the top menu, File -> Open Projects From File Systems…, click the “Directory…” button, navigate to the folder which contains the java files.

eclipse import projects from file system

To open Maven project:

Go to the top menu, File -> Import…, select Maven -> Existing Maven Projects, click Next. In the “Import Maven Projects”, click “Browse…” button,  navigate to the folder that contains pom.xml.

eclipse import maven project


2.  Remove the red mark on Project in Package Explorer

If you see red cross or exclamation mark on the project in the Package Explorer, open “problem” to  find the errors and fix them.

eclipse red sign on project

Go to the top menu, Window -> Show View -> Problems. If “Problems” is not in the right list, select “Others…” and select the Problems.

eclipse select problems view

In the “problem” tab, expand and read the details about the errors. Fix the error by its description. If you think the error can be ignored, right click and delete it. 

eclipse problems tab


3. Change System Library

When you open somebody else’s projects in your eclipse, you may see the java files have the errors to import Java packages. To fix this, you need to change system library for the project.

In the Package Explorer, right click the project -> build path -> configure build path…, click Libraries tab.   Highlight the “JRE System library”, click “Remove” button.

eclipse jre system library

Then click “Add Library…” button, select the “JRE System Library”, click “Next”. Add the installed JDK on your computer.

eclipse add jre system library

Then click “Apply and Close”. The errors should be gone.

If it is a maven project, the jdk might be defined in pom.xml, as shown below. You should change the version accordingly.  

<properties>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
</properties>


4. Run JUnit

If you wand to add JUnit test cases in the project, you have to add JUnit Library first.

Right click the project -> build path -> configure build path…, select “Libraries” tab. Click “Add Library…” button. In “Add Library” pop up, select “Junit”, click “Next”. In the next window, select “Junit 4”  or “Junit 5” available in eclipse. Click “Finish”.  

eclipse add junit

To add JUnit test case, right click project, New -> JUnit Test Case.

eclipse add junit test

To run the test cases, right click the project , Run as ->JUnit Test.

run junit test


5. Import External JARs

Some projects require external jar files, such as gson, Java fx, derby embedded db etc. First, you need to download the jar files online. Then right click the project -> build path -> configure build path…, select “Libraries” tab.  Click “Add External JARs…” button at right, navigate to the folder where the jar files are  located. Select the jar file, click “OK” button.

add external jars


6. Turn on Autosave in eclipse settings

When you make any changes in the code, you can run it without click saving button. This is autosave. You can turn on autosave in the preferences.

One way is Window->Preferences -> General->Editors->Autosave, check the box of “Enable autosave for dirty editors”.

Alternatively, Go to top menu, Window -> Preferences -> Run/Debug -> Launching. In “Save required dirty editors before launching”, check the radio button “Always”.

eclipse autosave


7. Run with Arguments

If you want to pass the values to the program args (the same as how you run from command line), you can define the arguments in eclipse:

Right click the project, select Run As -> Run configurations…

run configurations

select “Arguments” tab, enter values in one line, separated with space.

eclipse add arguments


8. Increase JVM heap size

If your program read in big file and run out of memory, you need increase the heap size.

Right click the project, select Run As -> Run configurations. Click “Arguments” tab. In VM Argument area, Increase heap size like this “-Xms4096m -Xmx4096m”

increase heap size


9. Find the Command Line to Run the Program

Sometime after you compile the code and run successfully in eclipse, you want run from Java programs (eg, multi-threading program) from command lines. If you run into errors such as Java class not found, you can get the command line arguments from eclipse.   

Go to the top menu, Window -> Show View -> Others…, select “Debug” in window “Show View” .  The Debug tab will appear next to Console.

debug tab

Right click the last line in Debug -> properties

eclipse debug properties

The “Properties for” window will show the Path and Command Line. You can copy this line and paste to your cmd window (Windows) or terminal (Mac) to run the java command.


10.  Add Tomcat Server

When you build web applications or web services, you need to install  web application server for test purpose. Apache Tomcat is one solution. You can download Apache tomcat zip file at http://tomcat.apache.org/.

Unzip the folder to the local drive. In Eclipse, Go to the top menu,  File -> New -> others…, select “Server”, click “Next”.  Select the version you downloaded and click “Finish”.

eclipse add tomcat server

To run the web project, right click the project, Run as -> run on server.

eclipse run on server


How to remove red symbols on project (if you have already tried many things)?

  1. Open Problems view

    If you have tried things like remove and add system library, remove and add files or folders etc, and the red cross or exclamation is still there, Do this, go to the top menu, Window -> Show View -> Problems. If “Problems” is not in the right list, select “Others…” and select the Problems. The Problems view show up at the right lower part of window.
    eclipse red sign on projects

  2. Delete the error

    In the Problems view, expand and read the details about the errors. Fix the error if the error message makes sense to you. If that still doesn’t help, right click the error message and delete the message. 
    eclipse problems tab

Comments are closed