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?
One shortcut that really helps me, Eclipse has syntax suggestions, and if you type "main" into the terminal window and hit control + space, you can choose main method and it'll populate it complete with enclosed braces. Helpful if you're not always quick to remember syntax off the top of your head!
To get public static void main(String[] args) line in eclipse without typing the whole line type main and press Ctrl + space then, you will get the option for the main method select it.
To import a code template: Click Import to open the "Import Templates" browser. Select the relevant XML file containing the template information. Click Open.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With