如何制作一个新的 Eclipse 项目模板?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2414020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a new Eclipse project template?
提问by Mohit Deshpande
I am using a kind of framework where every time I make a new Java project. I have to arrange the files in the appropriate packages and reference the appropriate external JARlibraries. How do I make a new project template like in the New Project dialog under a new folder?
我使用一种框架,每次我创建一个新的 Java 项目。我必须在适当的包中安排文件并引用适当的外部JAR库。如何在新文件夹下的“新建项目”对话框中制作新项目模板?
采纳答案by Nevena
You need to write an Eclipse plugin for that, and concentrate on New Project Wizard. About writing Eclipse plugins, it is covered in Stack Overflow question How to write a plugin for Eclipse?.
您需要为此编写一个 Eclipse 插件,并专注于新建项目向导。关于编写 Eclipse 插件,堆栈溢出问题如何为 Eclipse 编写插件?.
回答by Mark Storer
I've just done a bit of research on this for our own nefarious purposes, and found the answer.
为了我们自己的邪恶目的,我刚刚对此进行了一些研究,并找到了答案。
You need to create an Eclipse plugin that uses the org.eclipse.ui.newWizards
package. You can define your own category or use an existing one once you find the category ID. To create a new projectwizard rather than a new resourcewizard, you need to set the "project=true".
您需要创建一个使用该org.eclipse.ui.newWizards
包的 Eclipse 插件。找到类别 ID 后,您可以定义自己的类别或使用现有类别。要创建新项目向导而不是新资源向导,您需要设置“project=true”。
Also, your plugin must contain a class that implement org.eclipse.ui.INewWizard
. Clicking on the class link from the plugin.xml
editor will do the trick.
此外,您的插件必须包含一个实现org.eclipse.ui.INewWizard
. 单击plugin.xml
编辑器中的类链接即可解决问题。
That class must do all the work in the performFinish
override, and must return true to indicate that it actually did its thing and the wizard can close. This is where you create files, directories, set natures, and so forth.
该类必须完成performFinish
覆盖中的所有工作,并且必须返回 true 以指示它确实完成了它的工作并且向导可以关闭。您可以在此处创建文件、目录、设置性质等。