Update external libraries with intellij and java

Viewed 81764

I'm using some Apache jars, I'll make changes to the JAR's every so often.

These JARs are listed as external libs in intellij (i.e the classpath is looking to the install dir of the JAR's). Well when I make the changes intellij doesn't seem to know about the new implementation. I have to remove the jar as an external library and re-ad it.

Does anyone know what I have to do so intellij picks the changes up automatically? I've done clean and rebuild project but it had little effect.

7 Answers

Intellij Idea stores information about external libraries in .idea/libraries/ folder in xml files for each added lib or jar directory. Changing modification time of such xml file will trigger Intellij Idea to reindexing libraries. So that one will work:

touch .idea/libraries/libs.xml

I have found that if all else fails, you can simply delete the .idea folder inside your project and reopen the project - not an elegant solution, but it seems to work well enough in the extreme scenario.

Beside the GUI way you can directly edit .idea/libraries/lib.xml. You can even edit it right away in the IDE when choosing Project or Project Files in the top left corner.

The problem I had was in reloading an updated local plugin with the same version.
Use F4 and go to Libraries, click the library and note the location of the source jar. The library can be deleted by right-clicking and "delete". (I forget, you may have to also delete the cached lib from /.gradle/caches/modules2/files2.1) The cached source will stick around in IJ though, so the cache jar file must be deleted via File Manager. If it is "sticky" then use Windows Resource Manager to find the process preventing it from being deleted. In RM click CPU and search in Associated Handles for the jar, then right-click and kill the process.

As mentioned by @maheeka in the question's comments, if the project is a Maven project, the simplest way to achieve updating changed external libraries is to right-click on the project, and select Maven > Reload project.

You can actually see IntelliJ re-indexing the changed libraries individually during the operation in the bottom right status bar.

Tested on v2021.1 Ultimate.

Related