void (List<VirtualFile> jars) { final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel(); final LibraryTable.ModifiableModel tableModel = model.getModuleLibraryTable().getModifiableModel(); for (VirtualFile jar : jars) { final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(jar); if (jarRoot != null) { OrderRootType rootType = OrderRootType.CLASSES; String libName = "Grab:" + jar.getName(); for (String classifier : ContainerUtil.ar("sources", "source", "src")) { if (libName.endsWith("-" + classifier + ".jar")) { rootType = OrderRootType.SOURCES; libName = StringUtil.trimEnd(libName, "-" + classifier + ".jar") + ".jar"; } } Library library = tableModel.getLibraryByName(libName); if (library == null) { library = tableModel.createLibrary(libName); } final Library.ModifiableModel libModel = library.getModifiableModel(); for (String url : libModel.getUrls(rootType)) { libModel.removeRoot(url, rootType); } libModel.addRoot(jarRoot, rootType); libModel.commit(); } } tableModel.commit(); model.commit(); }