Search code examples
javaeclipseeclipse-jdt

Change Eclipse template for auto-generated main method?


When I create a new class in Eclipse Juno and auto-add a main method, I get the following:

public class Example {

  /**
   * @param args
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub

  }    
}

I would like to edit this method template to add throws Exception.

I tried editing the template at Preferences > Java > Editor > Templates > "main", however this doesn't affect the scenario above. Instead, this configures the code which is inserted when I type "main" and press Ctrl+Space.

Is this possible?


Solution

  • The only way I know for creating your own new class / new project template, is by creating your own plugin. This requires some effort. I am not sure if it is worth doing it only for adding a throw to main.

    Here is a tutorial for it.