public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject,String containerName,IPath[] inclusionFilters,IPath[] exclusionFilters,String outputLocation) throws CoreException {
  IProject project=jproject.getProject();
  IContainer container=null;
  if (containerName == null || containerName.length() == 0) {
    container=project;
  }
 else {
    IFolder folder=project.getFolder(containerName);
    if (!folder.exists()) {
      CoreUtility.createFolder(folder,false,true,null);
    }
    container=folder;
  }
  IPackageFragmentRoot root=jproject.getPackageFragmentRoot(container);
  IPath outputPath=null;
  if (outputLocation != null) {
    IFolder folder=project.getFolder(outputLocation);
    if (!folder.exists()) {
      CoreUtility.createFolder(folder,false,true,null);
    }
    outputPath=folder.getFullPath();
  }
  IClasspathEntry cpe=JavaCore.newSourceEntry(root.getPath(),inclusionFilters,exclusionFilters,outputPath);
  addToClasspath(jproject,cpe);
  return root;
}

public static IPackageFragmentRoot addSourceContainer ( IJavaProject jproject , String containerName , IPath [ ] inclusionFilters , IPath [ ] exclusionFilters , String outputLocation ) throws CoreException { IProject project = jproject . getProject ( ) ; IContainer container = null ; if ( containerName == null || containerName . length ( ) == 0 ) { container = project ; } else { IFolder folder = project . getFolder ( containerName ) ; if ( ! folder . exists ( ) ) { CoreUtility . createFolder ( folder , false , true , null ) ; } container = folder ; } IPackageFragmentRoot root = jproject . getPackageFragmentRoot ( container ) ; IPath outputPath = null ; if ( outputLocation != null ) { IFolder folder = project . getFolder ( outputLocation ) ; if ( ! folder . exists ( ) ) { CoreUtility . createFolder ( folder , false , true , null ) ; } outputPath = folder . getFullPath ( ) ; } IClasspathEntry cpe = JavaCore . newSourceEntry ( root . getPath ( ) , inclusionFilters , exclusionFilters , outputPath ) ; addToClasspath ( jproject , cpe ) ; return root ; }
adds a source container to a ijavaproject .
