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

1 comment
Comment actions Permalink

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:

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



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Please sign in to leave a comment.