public static IPackageFragmentRoot addLibraryWithImport(IJavaProject jproject,IPath jarPath,IPath sourceAttachPath,IPath sourceAttachRoot) throws IOException, CoreException {
  IProject project=jproject.getProject();
  IFile newFile=project.getFile(jarPath.lastSegment());
  InputStream inputStream=null;
  try {
    inputStream=new FileInputStream(jarPath.toFile());
    newFile.create(inputStream,true,null);
  }
  finally {
    if (inputStream != null) {
      try {
        inputStream.close();
      }
 catch (      IOException e) {
      }
    }
  }
  return addLibrary(jproject,newFile.getFullPath(),sourceAttachPath,sourceAttachRoot);
}

public static IPackageFragmentRoot addLibraryWithImport ( IJavaProject jproject , IPath jarPath , IPath sourceAttachPath , IPath sourceAttachRoot ) throws IOException , CoreException { IProject project = jproject . getProject ( ) ; IFile newFile = project . getFile ( jarPath . lastSegment ( ) ) ; InputStream inputStream = null ; try { inputStream = new FileInputStream ( jarPath . toFile ( ) ) ; newFile . create ( inputStream , true , null ) ; } finally { if ( inputStream != null ) { try { inputStream . close ( ) ; } catch ( IOException e ) { } } } return addLibrary ( jproject , newFile . getFullPath ( ) , sourceAttachPath , sourceAttachRoot ) ; }
copies the library into the project and adds it as library entry .
