Adding a project library to a module automagically...
Okay, so i have created a project level library as follows:
and i add contents to the library as follows:
After this, i see my library in the 'Use project library' panel of the Project | Library (Classpath) config panel. Currently its unchecked. So, i add the following to check it for a particular module:
Okay, now the library is checked and all appears in order.
Unfortunately, the library doesnt appear to work. ie: the classes contained in the jar file are not found during the compilation process. I run into the same problem when creating a Global library. I have noticed that when i manually create a library, IntelliJ does some indexing of the jar file. I suspect that this is not happening for me....
Any suggestions?
Cheers,
-Daniel
http://www.cenqua.com
Please sign in to leave a comment.
I am having the same problem. I would be interested in any suggestions as well.
Or have you found a solution in the meantime, Daniel?
--Etienne
Hi,
No, unfortunately I have not found any solutions, and have put that portion of the plugin to one side until I can find some more information.
I will post anything I find to this thread.
Cheers,
-Daniel
http://www.cenqua.com
The problem is that you add jar file from the LocalFileSystem. In this file system this is merely a file. Instead we need to create a library root inside the jar in order to be able to explore its contents. So the procedure of obtaining a VirtualFile is as following
String url = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, ]]>) + JarFileSystem.JAR_SEPARATOR;
VirtualFile jarVirtualFile = VirtualFileManager.getInstance().findFileByUrl(url);
The jarVirtualFile.getFileSystem() will return a JarFileSystem instead of LocalFileSystem. Note also that when constructing the url, the path to jar file should have forward slashes ('/') as a file separator:
"C:/work/lib/mylib.jar"
Hi Eugene
Thank you very much for your answer and also for your explanation. It works very smoothly now!
--Etienne
You are welcome :)
hi ...
i have a somewhat related question...
i want to check if a project-library is selected in an module.
there must be an api i think, because the library settings screen shows the checkmarks.
can you give me a hint??
thanks
christian
There's a LibraryTableRegistrar class:
com.intellij.openapi.roots.libraries.LibraryTablesRegistrar
You ca use its methods to obtain library tables of various "levels" (application, project, module, or a custom level)
Hello Eugene,
thank you.
now i use the ModuleRootManager to obtain a module and from that module i fetch the
OrderEntries. These entries i search for LibraryOrderEntrys on project level. That seem to be the
currently selected libraries of a module.
Is this the best way?
thanks
christian koestlin
Depending on what you need. If you need to answer the question "what project-level libraries are currently attached directly to the module", then this is the right way. Don't forget that the libraries can be "exported" by a module and thus visible to modules that depend on this module.
ok cool ...
what i mean by checked is: a library is visible in the libraries pane (e.g. at project libraries) and checked there (contributing
to the classpath of the module)
i want to use this function in a very simple maven pom dependency <-> irida classpath sync plugin.
so i think im ok when i dont check the transitive module dependencies.
but just for the curiosity .. does some helper class exist that answers the question is a library with the name xyz in the classpath of a module?
thanks again for the real fast answer
christian koestlin
>does some helper class exist that answers the question is a library with the name xyz in the classpath of a module?
No there's no such helper...
you are welcome :)
Hi ...
here is another question in the context of librarytable:
i want to create a library on module level.
i have no problems anymore with libraries on project-level.
i can simply create them with the library table that i can get via project.getComponent(LibraryTable.class). But i seem not to be able to get the library table for the module-level libraries (first try was to call getComponent on a module).
second take was the LibraryTablesRegistrar#getLibraryTableByLevel but i dont seem to get to the module-table.
another possibility would be to add the library directly as a LibraryOrderEntry. But i dont know how to create an object implementing this interface.