Update external libraries with intellij and java
I'm u开发者_StackOverflowsing 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.
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
.
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.
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.
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.
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.
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.
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.
精彩评论