How to properly add a jar library to a module programmatically?

I'm currently trying to add a third party jar to my module programatically. So far, adding the library works, I can see it under the "External Libraries" in the project, the code I'm using is

  private def createLibraryEntry(rootModel : ModifiableRootModel, jarFile : VirtualFile, name : String) : Library = {     val libraryTable = rootModel.getModuleLibraryTable     val libraryTableModel = libraryTable.getModifiableModel     val library = libraryTableModel.createLibrary(name)     val libraryModel = library.getModifiableModel     libraryModel.addRoot(jarFile, OrderRootType.CLASSES)     libraryModel.commit()     libraryTableModel.commit()     library   }



Later on in a readWriteAction I also call rootModel.commit(). However, despite being visible under the "External Libraries", nothing else happens, put it another way: the library is there and seems to be added to the module but i cannot access the classes and the like. Also, I cannot not see a dedicated entry for my library in the Libraries entry in the Module Settings (although I do not know whether an entry must be there or not). Anyway, can anybody help me with this problem?


Update: what i clarified, the entry in the Libraries section of the Module Settings is not necessary. And what I also realized, under "External Libraries", it shows my library with the jar but it doesn't say "(library home)"; I think this is the problem...


Thanks,

Phil

PS: I already checked the forum but so far, I couldn't find an answer on that particular problem, so thanks a lot in advance!

Message was edited by: Philipp Zech

1 comment
Comment actions Permalink

Apparaently, I was making the same mistake as described in this post:

http://devnet.jetbrains.net/message/5310983#5310983

Instaed of adding an instance of a JarFile to the LibraryModel, I attempted to just add a VirtualFile.

Cheers,

Phil

0

Please sign in to leave a comment.