public static void addClassPath(IJavaProject project, String jarPath) {
try {
IClasspathEntry[] oldClassPaths = project.getRawClasspath();
//if already exists the jar file then return
for (IClasspathEntry iClasspathEntry : oldClassPaths) {
if (iClasspathEntry.getPath().toOSString().equals(jarPath)) {
return;
}
}
IClasspathEntry jreLibrary = JavaCore.newLibraryEntry(new Path(
jarPath), null, null, false);
List list = new ArrayList();
list.addAll(Arrays.asList(jreLibrary));
list.addAll(Arrays.asList(oldClassPaths));
project.setRawClasspath((IClasspathEntry[]) list
.toArray(new IClasspathEntry[list.size()]), null);
refreshProject(project);
} catch (JavaModelException e) {
ELog.exception(e);
}
}
public static void refreshProject(IJavaProject project) { try { // the depth is infinite project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { ELog.exception(e); } }