简体   繁体   中英

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).

在此处输入图片说明

From that we can select project as Java Project or as per our requirement.

Now my question is, is it possible to add Custom Java Project as a project template in select Project Wizard ? 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.

For example, while creating new project, IoTSuiteSpecification is there in Select Project Wizard. 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.

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. If not, please refer to tutorials such as Your First Plugin or Google "Eclipse Plug-in Tutorial".

Step 1: Create an extension for your project wizard

  1. Go to plugin.xml -> Extensions -> Add -> org.eclipse.ui.newWizards, choose the "New File Wizard" template, click next.
  2. Name your Classes properly. I will call everything 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.
  3. Click Finish

Step 2: Implement the classes

After the previous step, you will have a package containing the wizard classes you just created. It should have two classes NewWizard and NewWizardPage .

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.

When you gather information from user, you should do some setup of your new project. Open class NewWizard , and find the function 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. It provides a good reference for how to do these. If you have no idea, read or just copy their code.

Step 3

That's it! Enjoy your new project wizard!

Examples

As an example, you can look at my project https://github.com/harperjiang/TeXDojo . This is a plugin I wrote for Eclipse to edit and compile latex files. It contains a complete project wizard implementation in the package LaTeXEditorPlugin/src/hao.tex.dojo.latexeditor.wizards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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