Eray Tuncer
Eray Tuncer

Reputation: 725

Creating a new Java project

I am able to create a default project in PDE just like mentioned here.

However I want to know how to create a Java project. How can I do that?

Upvotes: 2

Views: 314

Answers (3)

greg-449
greg-449

Reputation: 111142

As a minimum you need to add the Java project nature to the project you create. Use something like:

private void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException
{
    IProjectDescription description = proj.getDescription();

    String[] prevNatures = description.getNatureIds();

    String[] newNatures = new String[prevNatures.length + 1];

    System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);

    newNatures[prevNatures.length] = natureId;

    description.setNatureIds(newNatures);

    proj.setDescription(description, monitor);
}

The nature id for a Java project is 'org.eclipse.jdt.core.javanature' (also in the JavaCore.NATURE_ID constant).

Note that this does not add the various builders that are normally used in a Java project. The IProjectDescription.setBuildSpec method adds those in a similar way. Create a command for the build spec with:

ICommand command = description.newCommand();
command.setBuilderName(builderID);

where 'builderId' is 'org.eclipse.jdt.core.javabuilder' for the main Java builder (JavaCore.BUILDER_ID constant).

All this information is stored in the '.project' file in the project root folder. This is an XML file which you can look at to see the set up of existing projects.

Upvotes: 2

Saagar Elias Jacky
Saagar Elias Jacky

Reputation: 2688

Please refer to New Project Creation Wizards

On the Plug-in Project page, use com.example.helloworld as the name for your project and check the box for Create a Java project (this should be the default). Leave the other settings on the page with their default settings and then click Next to accept the default plug-in project structure.

Upvotes: 0

SamTebbs33
SamTebbs33

Reputation: 5647

Window->Open Perspective->Java

then

File->New->Java Project (you may have to go via "Project..." to get to the "Java Project" option)

Upvotes: 0

Related Questions