[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] How to attach a SRC folder to a IJavaProject

Hi,
I've managed to create a IJavaProject.
Now I want to programmatically attach a SRC folder to it. This is what I tried:


IJavaModel javamodel = JavaCore.create(workspaceroot);
if(javamodel!=null)
{ javaProj = javamodel.getJavaProject(iProject.getName());



IPackageFragmentRoot[] allpackroots = null; int numpackroots = 0; if(javaProj!=null && javaProj.exists()) { try { allpackroots = javaProj.getAllPackageFragmentRoots(); } catch (JavaModelException e){ e.printStackTrace(); } }

  //Tryign to create my SRC folder under this IJavaProject
  if(allpackroots != null)
  { this.packFragRoot = allpackroots[0];
    try { this.packFragRoot.attachSource(new Path("src"),null,null); }
    catch (JavaModelException e) { e.printStackTrace(); }
  }
}	

But, I get a Java Model Exception in the line
"this.packFragRoot.attachSource(new Path("src"),null,null);"
With the following message :
"Java Model Status [Operation not supported for specified element type(s):[project root] [in myJavaProj]]"


Could anyone please suggest how to go about programmatically creating the SRC folder under the IJavaProject that I just created.

Thanks in advance.

Regards,
Nirmalya