Library.ModifiableModel - HOW-TO addRoot/removeRoot

Hi,

I need to remove a library (jar) from module libraries list, so I do:

Unfortunatelly the library named libURL (full path to it, prefixed jar:// and suffixed !/) is not removed from its root.

The same library was added calling:
addRoot(libURL, OrderRootType.CLASSES);

Could someone tell me please, what is wrong here?

Kind regards,

Pavlin

1 comment

Pavlin Zahariev wrote:

Hi,

I need to remove a library (jar) from module libraries list, so I do:

 ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
> ModifiableRootModel rootModel = rootManager.getModifiableModel();
> LibraryTable libTable = rootModel.getModuleLibraryTable();
> Library library = libTable.getLibraryByName(libName);
> Library.ModifiableModel libraryModel = library.getModifiableModel();
> libraryModel.removeRoot(libURL, OrderRootType.CLASSES);
> ]]>

Unfortunatelly the library named libURL (full path to it, prefixed jar://
and suffixed !/) is not removed from its root.

The same library was added calling:
addRoot(libURL, OrderRootType.CLASSES);

Could someone tell me please, what is wrong here?


To remove a library, call LibraryTable.removeLibrary().
To remove a root from library, call Library.ModifiableModel.removeRoot().
Do not forget to commit ModifiableModel afterwards.

Friendly,
Dmitry
--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

Please sign in to leave a comment.