Wiki

Clone wiki

BibSonomy / development / Eclipse Tips and Tricks

Templates

In order to create a new template, navigate to Window > Preferences > Java > Editor > Templates and click "New ...". Enter the desired name, description and pattern and press "Ok". You should now be able to use the template by entering the name and pressing Ctrl + Space, thus expanding it to the provided pattern.

Useful templates

Providing a Log object

private static final Log log = LogFactory.getLog(${primary_type_name}.class);${:import(org.apache.commons.logging.Log, org.apache.commons.logging.LogFactory)}

Singleton pattern

private static final ${primary_type_name} INSTANCE = new ${primary_type_name}();

/**
 * @return the @{link:${primary_type_name}} instance
 */
public static ${primary_type_name} getInstance() {
    return INSTANCE;
}

private ${primary_type_name}() {

}

Auto-import on save

Navigate to Window > Preferences > Java > Editor > Save Actions and assure "Perform the selected actions on save" and "Organize imports" are checked. This will

  • add missing classes to the import list
  • delete unused classes from the import list
  • alphabetically order the list

Organize static imports

Navigate to Window > Preferences > Java > Editor > Content Assist > Favorites. Create new types for 'org.bibsonomy.util.ValidationUtils' and 'org.junit.Assert'. Now, typing 'pres' and pressing Ctrl + Space should expand to 'present' and include the corresponding static import. (see here)

Maven run configurations

You can create run/debug configurations to simplify Maven usage in Eclipse. To do so, right click your project, navigate to Run As > Run configurations... (or Debug As > Debug configurations... respectively), then right click 'Maven Build' and choose 'New'.

Maven run config setup

  • Base directory: Either provide a specific configuration for every subproject and enter the projects location, or generalize by using '${project_loc}'.
  • Goals: As desired; configurations for 'install' and 'war:inplace' are reasonable, see the screenshot above for further ideas
  • Additionally you should check 'Refresh resources on completion' in the 'Resources' tab for the selected resource. This is especially useful for WEB-INF/lib and WEB-INF/classes.

Maven run config refresh

Updated