java - Create Source Folder Programmatically -


i have tried create 1 source folder in java project below code.

    iworkspaceroot root = resourcesplugin.getworkspace().getroot();     iproject project = root.getproject(projectname);     project.create(null);     project.open(null);     iprojectdescription description = project.getdescription();     description.setnatureids(new string[] { javacore.nature_id });     project.setdescription(description, null);     ijavaproject javaproject = javacore.create(project);      ifolder sourcefolder = project.getfolder("src");     sourcefolder.create(false, true, null);     ipackagefragmentroot root = javaproject.getpackagefragmentroot(sourcefolder);     iclasspathentry[] oldentries = javaproject.getrawclasspath();     iclasspathentry[] newentries = new iclasspathentry[oldentries.length + 1];     system.arraycopy(oldentries, 0, newentries, 0, oldentries.length);     newentries[oldentries.length] = javacore.newsourceentry(root.getpath());     javaproject.setrawclasspath(newentries, null); 

but giving java model exception last line : javaproject.setrawclasspath(newentries, null);

java model exception: java model status [cannot nest 'projectname/src' inside 'projectname'. enable nesting exclude 'src/' 'projectname']     @ org.eclipse.jdt.internal.core.javamodeloperation.runoperation(javamodeloperation.java:784)     @ org.eclipse.jdt.internal.core.javaproject.setrawclasspath(javaproject.java:3102)     @ org.eclipse.jdt.internal.core.javaproject.setrawclasspath(javaproject.java:3064)     @ org.eclipse.jdt.internal.core.javaproject.setrawclasspath(javaproject.java:3117) 

can 1 tell me how can create source folder programmatically?

when called javaproject.getpackagefragmentroot(), created build path project using source folder. skip it, can project-relative path ifolder instance , make newsourceentry that.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -