Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Programmatically creating a project ?
Programmatically creating a project ? [message #108677] Fri, 08 August 2003 04:38 Go to next message
Eclipse UserFriend
Originally posted by: mh.nixspam.com

How can I create an eclipse-project from my coding and set the nature ?
Does anyone have an example ?

Thanks

Mario
Re: Programmatically creating a project ? [message #108773 is a reply to message #108677] Fri, 08 August 2003 07:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tprumbs.atsistemas.com

To get started, have a look at the eclipse source.
E.g. BasicNewProjectResourceWizard (eclipse.ui) or
NewProjectCreationWizard (jdt.ui)

The code to create a new project will be s.th. like this:
....
IWorkspace w=ResourcesPlugin.getWorkspace();
IProject projHandle = w.getRoot().getProject("yourProjectName");
IProjectDescription desc=w.newProjectDescription(projHandle.getName());
desc.setLocation(yourPath);
projHandle.create(desc, monitor);
projHandle.open(monitor);
....

projHandle is your new Project. To add a Nature you'll have s.th. like this:
....
IProjectDescription desc = project.getDescription();
String[] prevNatures= desc.getNatureIds();
String[] newNatures= new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length]= YOUR_NATURE_ID;
desc.setNatureIds(newNatures);
project.setDescription(desc, monitor);
....

The JDT wizards are a bit complex but after a while you'll find the example
what you look for. Most of it is internal so shouldn't be extended. But the
ResourceWizards are open for reusage.

Hope that helps :)
Thorsten


"Mario Herger" <mh@nixspam.com> escribi
Re: Programmatically creating a project ? [message #109439 is a reply to message #108773] Mon, 11 August 2003 05:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mh.nixspam.com

"Thorsten Prumbs" <tprumbs@atsistemas.com> wrote in message
news:bh007a$89g$1@eclipse.org...
> To get started, have a look at the eclipse source.
> E.g. BasicNewProjectResourceWizard (eclipse.ui) or
> NewProjectCreationWizard (jdt.ui)
>
> The code to create a new project will be s.th. like this:
> ...
> IWorkspace w=ResourcesPlugin.getWorkspace();
> IProject projHandle = w.getRoot().getProject("yourProjectName");
> IProjectDescription desc=w.newProjectDescription(projHandle.getName());
> desc.setLocation(yourPath);
> projHandle.create(desc, monitor);
> projHandle.open(monitor);
> ...
>
> projHandle is your new Project. To add a Nature you'll have s.th. like
this:
> ...
> IProjectDescription desc = project.getDescription();
> String[] prevNatures= desc.getNatureIds();
> String[] newNatures= new String[prevNatures.length + 1];
> System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
> newNatures[prevNatures.length]= YOUR_NATURE_ID;
> desc.setNatureIds(newNatures);
> project.setDescription(desc, monitor);
> ...
>
> The JDT wizards are a bit complex but after a while you'll find the
example
> what you look for. Most of it is internal so shouldn't be extended. But
the
> ResourceWizards are open for reusage.

Thanks, that looks already good, but I get with the following lines at the
last in this snippet an "Invalid project description." error.

---snip---
IPath path = new Path("C:/temp");
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProject newProjectHandle = workspace.getRoot().getProject("ABC123");
IProjectDescription description =
workspace.newProjectDescription(newProjectHandle.getName());
description.setLocation(path);
newProjectHandle.create(description, monitor);

---snap---

Any ideas?

Mario
Re: Programmatically creating a project ? [message #109710 is a reply to message #109439] Mon, 11 August 2003 15:03 Go to previous message
Eclipse UserFriend
Originally posted by: John_Arthorne.oti.com_

That exception will contain a MultiStatus object, and its children will
tell you exactly what you did wrong. An easy way to see all the details
is to log the status object (YourPlugin.getLog().log(IStatus)), and then
see all the details in the log file.
--


Mario Herger wrote:
>
> Thanks, that looks already good, but I get with the following lines at the
> last in this snippet an "Invalid project description." error.
>
> ---snip---
> IPath path = new Path("C:/temp");
> IWorkspace workspace = ResourcesPlugin.getWorkspace();
> final IProject newProjectHandle = workspace.getRoot().getProject("ABC123");
> IProjectDescription description =
> workspace.newProjectDescription(newProjectHandle.getName());
> description.setLocation(path);
> newProjectHandle.create(description, monitor);
>
> ---snap---
>
> Any ideas?
>
> Mario
>
>
Previous Topic:Export filter?
Next Topic:Java build path - "require plug-in entries"
Goto Forum:
  


Current Time: Sat Nov 08 21:09:39 EST 2025

Powered by FUDForum. Page generated in 0.02926 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top