Eclipse:Java类模板
在Eclipse 3.5中,在Windows – > Preferences – > Java> Editor – > Templates下,我可以添加代码模板。 但是,这些模板只能包含我可以插入到现有Java类中的代码段。
是否可以为整个Java类创建模板,我可以使用File – > New – > My-Java-Class添加这些模板?
您可以在eclipse中添加“ 新文件向导 ”,但是您需要编写一个新插件来执行此操作。 我不知道在运行时以MS Office模板的方式执行此操作的简单方法,我认为这是您正在尝试执行的操作。
一个新的模板机制可能是一个有用的插件,但我找不到任何已经这样做的东西。
你可以做的是添加一个普通的代码快捷方式(java – > editor – > templates),
即使编辑器模板“newcustomclass”成为您正在讨论的类的内容。
然后以正常方式创建新的java类,删除所有内容,然后使用“newcustomclass”代码模板创建新的自动java类。
这是一个简单exception类的示例:
public class ${enclosing_type} extends Exception { /** * Constructs with the given throwable * @param t the throwable to throw */ public ${enclosing_type}(Throwable t) { super(t); } /** * Constructs with the given message * @param message the message of the exception */ public ${enclosing_type}(String message) { super(message); } /** * Constructs with the given message and the original throwable cause * @param message the message of the exception * @param t the original throwable */ public ${enclosing_type}(String message, Throwable t) { super(message, t); } }
是! 窗口 – >首选项 – > Java – >代码样式 – >代码模板
在树面板中选择“代码”和新的Java文件。
您可以尝试使用这个eclipse 插件,它可以创建一个包含许多可配置参数的Java类,例如注释或XML配置。
- 主线程java.lang.NoClassDefFoundError中的exception
- Maven / Eclipse:在类路径中找不到任何META-INF / persistence.xml文件
- Android图片库视图的来源,包括缩放缩放,触摸滑动等
- 如何在Eclipse中运行具有main()的单个Java文件,而无需创建整个Java项目?
- 如何在我的eclipse中调试远程应用程序
- 找不到我打开的文件的来源
- 如何在Eclipse的Java EE透视图中隐藏引用的库?
- 使用TestSuite时,我可以避免在eclipse中运行两次junit测试吗?
- 安装Maven Integration for Eclipse时出错