Change Eclipse template for auto-generated main method?

When I create a new class in Eclipse Juno and automatically add the 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 a throws Exception .

I tried changing the template in Preferences> Java> Editor> Templates> General , however this does not affect the scenario described above. Instead, it sets up the code, which is inserted when I type "main" and press Ctrl + Space .

Is it possible?

+6
source share
2 answers

The only way I know to create your own new class / new project template is to create your own plugin. It takes some effort. I'm not sure if this is only worth adding a throw to main.

Here is a tutorial for him.

+3
source

I know it's too late for an answer. Hope someone else finds this helpful.

I tried to do it the exact same way. I wanted to do something like

 public class Example { public static void main(String[] args) { Example sol = new Example(); } } 

I ended up setting up a code template that automatically generates the above for me.

Edit the template in Settings> Java> Code Style> Code Templates> Code> Class Body> Edit

By adding the following template, I will generate what I need

  public static void main(String[] args) { ${type_name} sol = new ${type_name}(); } 

For your use case, the below template should do it.

  public static void main(String[] args) throws Exception { } 
0
source

Source: https://habr.com/ru/post/945547/


All Articles