Steve
Steve

Reputation: 21499

Update external libraries with intellij and java

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.

Upvotes: 44

Views: 133749

Answers (10)

Taulant
Taulant

Reputation: 205

For me, this does the trick: Rightclick on pom file -> Maven -> Reload project

Upvotes: 3

Flyper_Fire
Flyper_Fire

Reputation: 1

new intellij idea go to project structure open external lib folder, right click on SDK or JDK, open lib settings, project setting, change SDK do you want. Or easiest click Ctrl+Alt+Shift+S and setting project SDK.

Upvotes: 0

Akshay Verma
Akshay Verma

Reputation: 31

IntelliJ generates a ".idea" folder. Delete it. Restart IntelliJ and rebuild/reimport your code.

Risks - It will also delete your shelved files + version control directory mapping.

Upvotes: 2

NotSoOldNick
NotSoOldNick

Reputation: 593

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.

Upvotes: 8

Jay
Jay

Reputation: 193

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.

Upvotes: 1

Jon Thoms
Jon Thoms

Reputation: 10759

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.

Upvotes: 4

karlsebal
karlsebal

Reputation: 1731

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.

Upvotes: 1

Dmitry R.
Dmitry R.

Reputation: 51

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

Upvotes: 4

chepukha
chepukha

Reputation: 2489

You can go to Preferences -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing and check the box that says Import Maven projects automatically.

In Mac, you can do Command + Shift + A, then enter the action reimport, then click on Reimport all Maven projects.

Upvotes: 34

Prasanna
Prasanna

Reputation: 11544

I generally place all my Jars under one folder and will configure the folder in Intellij. So whenever you add Jars into that folder Intellij automatically picks up.

  • Go To Project Structure.
  • Choose Libraries in the Left Pane
  • Delete all the existing ones.
  • Now add a new library by pressing on the + symbol in the middle lane.
  • Give a name to it. Now choose 'Attach Jar
  • Directories' Locate your library folder.

And that's it you are done. Try adding new Jars and it will automatically gets updated in your project.

Upvotes: 8

Related Questions