Programmatically add a library
Is there a way to add a library to a global or project list from inside a plugin? I've tried to do it by using
Library lib = LibraryTableUtil.getLibraryTable().getModifiableModel().createLibrary("somename");
lib.getModifiableModel().addRoot(vf, OrderRootType.CLASSES);
where vf is the instance of VirtualFile pointing to a class jar.
But this does not seem to work. Anything I am doing wrong?
Thanks
Please sign in to leave a comment.
Yes,
One needs to add library as virtual file in jar file system, like
libraryModel.addRoot(
VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL,
dataFile.getPath() + "/appserv-jstl.jar" + JarFileSystem.JAR_SEPARATOR),
OrderRootType.CLASSES
);
Also do not forget to commit libraryModel
Alex Antonov wrote:
--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"