Skip to content

Instantly share code, notes, and snippets.

@lucamartellucci
Last active March 11, 2016 16:08
Show Gist options
  • Save lucamartellucci/cc87d0a2be9fbb589b6c to your computer and use it in GitHub Desktop.
Save lucamartellucci/cc87d0a2be9fbb589b6c to your computer and use it in GitHub Desktop.
How to setup Eclipse for Java Development

Eclipse Tips

Add static imports to the favorite list

To speed up the import of static methods in a Java class we need to populate the Eclipse's "Content Assist, Favorites"

Window > Preferences > Java > Editor > Content Assist > Favorites

In mine, I have the following entries (when adding, use "New Type" and omit the .*):

  • org.hamcrest.Matchers.*
  • org.hamcrest.CoreMatchers.*
  • org.junit.*
  • org.junit.Assert.*
  • org.junit.Assume.*
  • org.junit.matchers.JUnitMatchers.*
  • org.mockito.Matchers.*
  • org.mockito.Mock.*
  • org.mockito.Mockito.*
  • org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*
  • org.springframework.test.web.servlet.result.MockMvcResultMatchers.*

Source Stack Overflow:

Keyboard shortcuts cheat sheet

Keys Action
ALT + SHIFT + X + J exec the java app
ALT + SHIFT + X + T exec the test
ALT + SHIFT + X + M exec maven
ALT + SHIFT + S open source menu
ALT + SHIFT + T open refactor menu
ALT + SHIFT + R rename
ALT + SHIFT + I inline
CTRL + 1 quick fix
ALT + F5 update maven project
ALT * SHIFT + UP selects a string

Templates

Window > Preferences > Java > Editor > Templates

SLF4J template

${:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}
private static final Logger LOGGER = LoggerFactory.getLogger(${enclosing_type}.class);

Create a new ArrayList

${:import(java.util.List,
  java.util.ArrayList)} 
List<${argType}> ${newName} = new ArrayList<${argType}>(); 

Format a String

usage: ALT * SHIFT + UP to select the string and double CTRL + SPACE

${:import(java.text.MessageFormat)} 
 MessageFormat.format(${word_selection}, ${cursor});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment