How to add project to Create Project Wizard in Eclipse - java

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
Go to plugin.xml -> Extensions -> Add -> org.eclipse.ui.newWizards, choose the "New File Wizard" template, click next.
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.
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

Related

How i can i identify the project type as an eclipse plug-in?

I want to identify the type (java/c/...) of the currently selected project from an Eclipse plug-in; If possible some other information also (used libraries and what not), basically all the information surrounding the project.
I have been searching on google and here for a couple of hours now, to no avail. Can i even access the information i want without selecting some bogus Extension Point (none of the ones listed seem to fit what i want to do)? I mean, i don't want to actually add anything to Eclipse right now, i just want to print out that stuff into the console. (start small and stuff)
Sorry for the long rant, but i don't know how to better express my problem right now.
A lot of this information is stored in the .project file in the project folder. The correct way to access the information is via the IProject object for the project.
The IProject.getDescription method returns you a IProjectDescription containing information about the project.
To determine the type of project you need to look at the natures that are defined in the project description. The IProjectDescription.getNatureIds() method returns an array of the nature ids. A Java project will have the org.eclipse.jdt.core.javanature and a plug-in will have org.eclipse.pde.PluginNature (and a Java plug-in will have both these natures).
To find the IProject. If you have a selection in something like Package or Project Explorer try:
IResource resource = (IResource)Platform.getAdapterManager().getAdapter(obj, IResource.class);
or
IFile file = (IFile)Platform.getAdapterManager().getAdapter(obj, IFile.class);
the getProject() method of these interfaces gives you the IProject. You may also just be able to do:
IProject project = (IProject)Platform.getAdapterManager().getAdapter(obj, IProject.class);
Platform in the above is org.eclipse.core.runtime.Platform (there are other Platform classes in Eclipse so be sure to get the correct one).
If you just have a project name then use:
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);

How to build 4 projects(example) and make them access each other?

How do I make something like 4 project and make them see each other, like a .xhtml to a Bean and a Bean to the interface that implements the method to save or read something from the database?
The other solution would be to:
use only one workspace (meaning each components see each other)
define task context with Mylyn in order to switch from one component to another and see only what you need.
You cannot split workspace. You can create as many workspaces as you want and add there as many projects as you want. To create new workspace just create directory and then start eclipse and give it this directory as a workspace. It will do everything automatically.
Unfortunately your second question is unclear.
Right-click on the project; choose Properties. Click on Project References and select the other projects.

How to import existing project into Workplace in Eclipse?

I am trying to follow Eclipse instructions to create a Hello World SWT application. I have the following instruction:
Import the SWT project from the main
menu via File > Import..., and select
Existing Projects into Workspace.
Specify the archive file you
downloaded and click Finish. This will
create the org.eclipse.swt project
which we will need to compile and run
the application.
I have troubles with that. In the "File" menu I see "Import...". When I click the "Import...", I do not see "Existing Project into Workspace". Instead of that I see "Select an import source:" after which I see a text field. After that I see a field with the following folders: General, CVS, Run/Debug, Tasks, Team, XML.
Can anybody help me with that, pleas?
You need to expand General.
If you expand the 'General' node (folder) you will see 'Existing projects into workspace' as an option. Select that and click on Next.
Eclipse has the wonderful search functionality on most of its important screens. Even if you don't know where exactly it is, you can type it and it appears. In this case type "Existing" into the text field above the list and you'll see what you are looking for.

Getting a Class from another project programatically

I want to access a class which is present in another project . For that i use java reflections,but first i need to get the class object which is in another project.I want to get it programatically.I can do that like right click on my project then go to build configure path and then to project tab and add project.I want to do it programmatically .How can i do that?Help
You need a custom class loader.
tutorial link1
tutorial link 2
I think you can do it by creating a jar of the dependent project and adding it to class path before you run your application.
It seams you are working in eclipse and want do use the classes from projet B in projet A, is it so?
If so you could specify in eclipse that project A depends from project B by adding the project in the 'java build properties'.
Do get the right answer, you ask to be more specific in your question like Steven wrote.

Programmatically generate an Eclipse project

I use eclipse to work on an application which was originally created independently of eclipse. As such, the application's directory structure is decidedly not eclipse-friendly.
I want to programmatically generate a project for the application. The .project and .classpath files are easy enough to figure out, and I've learned that projects are stored in the workspace under <workspace>/.metadata/.plugins/org.eclipse.core.resources/.projects
Unfortunately, some of the files under here (particularly .location) seem to be encoded in some kind of binary format. On a hunch I tried to deserialize it using ObjectInputStream - no dice. So it doesn't appear to be a serialized java object.
My question is: is there a way to generate these files automatically?
For the curious, the error I get trying to deserialize the .location file is the following:
java.io.StreamCorruptedException: java.io.StreamCorruptedException: invalid stream header: 40B18B81
Update: My goal here is to be able to replace the New Java Project wizard with a command-line script or program. The reason is the application in question is actually a very large J2EE/weblogic application, which I like to break down into a largish (nearly 20) collection of subprojects. Complicating matters, we use clearcase for SCM and create a new branch for every release. This means I need to recreate these projects for every development view (branch) I create. This happens often enough to automate.
You should be able to accomplish this by writing a small Eclipse plugin. You could even extend it out to being a "headless" RCP app, and pass in the command line arguments you need.
The barebones code to create a project is:
IProgressMonitor progressMonitor = new NullProgressMonitor();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("DesiredProjectName");
project.create(progressMonitor);
project.open(progressMonitor);
Just take a look at the eclipse code for the Import Project wizard to give you a better idea of where to go with it.
Use AntEclipse
It can create eclipse projects from ant.
To create java project you can use JavaCore from org.eclipse.jdt.core.JavaCore. As a sourceProject you can use generic project item, which has been suggested by #James Van Huis
IJavaProject javaSourceProject = JavaCore.create(sourceProject);

Categories