Eclipse Tips and Tricks

This is a collection of Eclipse Tips and Tricks which I've learnt over time. You will be surprised how you can boost your productivity by learning just a few simple tecqniques!

A. How to choose the format of deployed applications

In order to run this trick, you need to install JBossAS tool from JBoss tools distribution. Once you have installed this component, select the JBoss AS perspective.


In the lower part of the screen, double click on the server. The jBoss runtime window will open with two tabs.

Select the "Deployment" tab and choose if you want to deploy the application as compressed archive or not.

Deploy Compress

B. How to deploy an application to a remote JBoss server

You need to to install JBossAS tool from JBoss tools distribution in order to run this tip.

1. From the File menu select New > Server and choose a JBoss server from the "JBoss Community" list.

2. In the next window will let you choose the local installation of JBoss server. This will be anyway needed for setting up the classpath of your project.

3. In the next window you will specify the location of the JBoss server. Choose as server behaviour "Remote system deployment" and select the Host using the "New Host" button.

Remote Deploy

4. Once connected to the host, choose the "Browse" button to browse the remote file system and pick up the JBoss home. If everything was correctly configured the "Test" button will verify the connection to the server.

C. How to debug JBoss remotely

Remote debugging of a Java application can be done using the Java Debugger (jdb) which is a dynamic, controlled, assignment-based debugging tool. It helps find and fix bugs in the Java language programs both locally and on the server. To use jdb in a J2EE application server you must first launch it with debugging enabled and attach to the server from the debugger through a JPDA port (Default port is 1044).

On JBoss, the debugger can be enabled by uncommenting this line in the file run.conf.bat (run.conf for Linux)

set "JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

After making sure JBoss is listening for incoming connections on port 8787, what is left is to tell Eclipse to connect to this port and you are ready to debug.

1. In Eclipse, navigate to Run > Debug

2. Select Remote Java Application, on the left column. Click New, on the bottom of the same column.

3. In the Create configuration screen you'll be prompted to enter some values. Start with a meaningful name. For Project, select the Java project that contains the source code you want to debug. Leave Connection Type in default, i.e. Standard (Socket Attach). For Host, enter the remote server hostname or IP address. For port, enter 8787 or the port you defined in your JBoss startup script.

Remote Debug

4. Click Apply

5. Make sure JBoss instance is running in debug mode. In the same screen click Debug. Eclipse should automatically take you to the Debug perspective and you should see a stack trace in the Debug view.

6. If you are not automatically taken to the Debug perspective, select Window > Open Perspective > Other and then click Debug.

D. How to use Ant to build your project

By default your project is rebuilt using the settins defined into your Properties | Build Path.

Sometimes you might find useful to use an Ant script to rebuild your project, so that you can use it even from outside the development environment. (A typical example of it could be using an Ant script for building both the development project and the production project).

At first open up the project properties to the 'Builders' section. Select the 'New' button and then in the next dialog choose 'Ant Build'.

In the 'Name' field enter the name you want to give the builder (Ex. Ant builder). Use the 'Browse Workspace' buttons to choose the location of the build file and the project root.


In the Targets tab you can configure the 'Clean' and 'Build' targets for your ant script. By convention, these targets are 'clean' and 'build'. For 'Clean' you will want the targets to clean the binaries and then rebuild the project. Once you have completed configuration, select 'OK'

Eclipse will now return you to the Builders section of the project properties dialog. Make sure that 'Java Builder' is is not checked in the list. Select 'OK' to apply the changes.


Now you have a completely Ant based project, no Eclipse compilation involved.

E. How to find quickly anything in Eclipse

One of the new-and-noteworthy features in Eclipse is Quick Access. Even if you're a fan of the mouse, this keyboard shortcut can save time and money.

The Quick Access -which is activated by Ctrl + 3 - is your window to anything; perspectives, views, open editors, commands, menus... just start typing, and it will show you the possible matches. It filters the most likely ones first, but if you press it again, will show all the possible matches that it knows about.


This is the quickest way to fine ANYTHING in Eclipse.

F. How to open an Eclipse file from Windows Explorer

Sometimes it can be necessary to operate on your project files from the Windows Explorer. The less efficient way to achieve it is by selecting the file properties, copying and pasting the file name in an Explorer window.

There's an easy way to do it, by configuring Explorer as External Tool.

In order to do it: Create an external tool with location ${env_var:SystemRoot}\explorer.exe and arguments /select,${resource_loc}.


Any selected file or directory can now be shown in the windows explorer.


G. Use Templates

Templates are one of the greatest time savers for Eclipse developers, yet not all users are aware of them. A template is a block of text which can be inserted in your code. It's much more powerful concept than cut and past since it may contain some dynamic pieces of code as well.

To see the list of built-in templates and to define new ones go to Window -> Preferences. Select Java -> Editor -> Templates. You can add your own templates here.

How to trigger a template: simply type in your editor the template code and press ctrl+space. For example type if you have defined a template named sql, just type sql and ctrl+space to activate the template.


Code template variables:

Eclipse can automatically fill out dynamic code by sniffing out variables in a template. Here are a few you should make yourself aware of

${cursor} - Place the cursor here after code completion
${enclosing_method} - Replace this with the method name where the code completion was called.
${enclosing_method_arguments} - Replace this with the enclosing method arguments
${enclosing_type} - The enclosing class name
${import} - Dynamically import some classes
${importStatic} - Same as above but with static imports
${time} - Current time
${todo} - The //TODO eclipse task

And here are a few interesting templates which can be imported in your project:

Singleton Template:

private static ${enclosing_type} singleton = new ${enclosing_type}();
private ${enclosing_type}() {}
public static ${enclosing_type} getInstance() {
  if (singleton == null) {
    singleton = new ${enclosing_type}();
  return singleton;

Log4j Template: (Defines a logger for the current class)

private static final Logger LOG = Logger.getLogger(${enclosing_type}.class);

H. How to set the proxy address in Eclipse

Well, most developers use Eclipse at work behind a proxy so it's absolutely a must to configure the proxy for keeping your libraries updated. Well the good news is that newer releases of Eclipse are able to read your browser's Proxy configuration, so it should work automatically.

If you have got an earlier Eclipse release or simply you want to customize your Proxy configuration, just point to Window > Preferences. Under the General element you can find the Network Connections panel which contains the proxy configuration.


Choose "Manual" to provide a custom proxy configuration. In the bottom part of the screen, you will be able to exclude the addresses which you don't want to hit with your proxy.


Popular posts from this blog

Reduce TIME_WAIT Socket Connections