[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform] Re: creating source folder

Parag wrote:
how do I create source folder programmatically.

Since you said programmatically, I'm assuming you're using the JDT APIs? You'll need to update your IJavaProject's raw classpath.


// get your IProject
IProject project = getProject();
// create the corresponding IJavaProject
IJavaProject ijp = JavaCore.create(project);
// get the folder
IFolder folder = project.getFolder("nameOfNewSrcFolder");
// create a new source entry for it
IClasspathEntry entry = JavaCore.newSourceEntry(folder.getFullPath());
// retrieve the project's current classpath
IClasspathEntry[] entries = ijp.getRawClasspath();
// create a new array with the original entries and the new source entry
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
newEntries[newEntries.length - 1] = entry;
ijp.setRawClasspath(newEntries, new NullProgressMonitor());

That should be the general gist of it.

Regards,
Rem