简体   繁体   English

如何将项目添加到 Eclipse 中的创建项目向导

[英]How to add project to Create Project Wizard in Eclipse

In Eclipse while creating new project, the following window opens (consider the area surrounded by red lines in the image).在 Eclipse 中创建新项目时,将打开以下窗口(考虑图像中被红线包围的区域)。

在此处输入图片说明

From that we can select project as Java Project or as per our requirement.从中我们可以选择项目作为 Java 项目或根据我们的要求。

Now my question is, is it possible to add Custom Java Project as a project template in select Project Wizard ?现在我的问题是,是否可以在 select Project Wizard 中添加 Custom Java Project作为项目模板? If yes, how?如果是,如何?

I want to create (please look the area surrounded by black lines in the image) a project having the name IoTSuiteSpecification as a default Project template in Select Project Wizard with mentioned four files and package.我想创建(请查看图像中黑线包围的区域)一个名为 IoTSuiteSpecification 的项目,作为选择项目向导中的默认项目模板,其中包含提到的四个文件和包。

For example, while creating new project, IoTSuiteSpecification is there in Select Project Wizard.例如,在创建新项目时,选择项目向导中有 IoTSuiteSpecification。 Let me know if you need more clarity.如果您需要更清楚,请告诉我。

As you did not provide detail about what function you want to implement.因为您没有提供有关您要实现的功能的详细信息。 This answer will just focus on how to create a new project wizard, but not the functionality details.这个答案将只关注如何创建一个新的项目向导,而不是功能细节。

In short: you need to write a plugin and install that on every Eclipse you want to have this function.简而言之:您需要编写一个插件并将其安装在您想要拥有此功能的每个 Eclipse 上。

I would like to keep this answer short, so the following content assumes you have basic knowledge about Eclipse Plugin Development, and have already created a plugin project.我想保持这个答案简短,所以下面的内容假设您有关于 Eclipse 插件开发的基本知识,并且已经创建了一个插件项目。 If not, please refer to tutorials such as Your First Plugin or Google "Eclipse Plug-in Tutorial".如果没有,请参考Your First Plugin或 Google “Eclipse Plug-in Tutorial”等教程。

Step 1: Create an extension for your project wizard步骤 1:为您的项目向导创建扩展

  1. Go to plugin.xml -> Extensions -> Add -> org.eclipse.ui.newWizards, choose the "New File Wizard" template, click next.进入 plugin.xml -> Extensions -> Add -> org.eclipse.ui.newWizards,选择“新建文件向导”模板,点击下一步。
  2. Name your Classes properly.正确命名您的类。 I will call everything NewWizard .我会称一切为NewWizard So the wizard class is NewWizard , and the wizard page class is NewWizardPage , etc. Do not care about the "File Extension" and "Initial File Name", we won't need them.所以向导类是NewWizard ,向导页面类是NewWizardPage等。不要关心“文件扩展名”和“初始文件名”,我们不需要它们。
  3. Click Finish单击完成

Step 2: Implement the classes第 2 步:实现类

After the previous step, you will have a package containing the wizard classes you just created.在上一步之后,您将拥有一个包含您刚刚创建的向导类的包。 It should have two classes NewWizard and NewWizardPage .它应该有两个类NewWizardNewWizardPage

First, you need to customize NewWizardPage to provide controls for your user to specify information such as Project name, etc. Refer to org.eclipse.ui.dialogs.WizardNewProjectCreationPage for an example of how to create a new Project Wizard page.首先,您需要自定义 NewWizardPage 为您的用户提供控件以指定项目名称等信息。有关如何创建新项目向导页面的示例,请参阅org.eclipse.ui.dialogs.WizardNewProjectCreationPage

When you gather information from user, you should do some setup of your new project.当您从用户那里收集信息时,您应该对新项目进行一些设置。 Open class NewWizard , and find the function performFinish .打开类NewWizard ,并找到函数performFinish In this function you should create your new project and setup it such as adding project natures.在此功能中,您应该创建新项目并进行设置,例如添加项目性质。 org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard is the eclipse wizard for creating a new general project. org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard是用于创建新的常规项目的 Eclipse 向导。 It provides a good reference for how to do these.它为如何执行这些操作提供了很好的参考。 If you have no idea, read or just copy their code.如果您不知道,请阅读或复制他们的代码。

Step 3第 3 步

That's it!就是这样! Enjoy your new project wizard!享受您的新项目向导吧!

Examples例子

As an example, you can look at my project https://github.com/harperjiang/TeXDojo .例如,您可以查看我的项目https://github.com/harperjiang/TeXDojo This is a plugin I wrote for Eclipse to edit and compile latex files.这是我为 Eclipse 编写的用于编辑和编译乳胶文件的插件。 It contains a complete project wizard implementation in the package LaTeXEditorPlugin/src/hao.tex.dojo.latexeditor.wizards它在包 LaTeXEditorPlugin/src/hao.tex.dojo.latexeditor.wizards 中包含一个完整的项目向导实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM