What's the correct procedure to add JARs into WEB-INF/lib directory in IntelliJ
Asked Answered
C

4

8

Say I have a Java web project and I need to place a couple of JARs into the WEB-INF/lib directory. In Eclipse, if you simply place those JARs there, Eclipse picks them up as on the classpath. However, IntelliJ doesn't seem to.

What is the correct way of adding those JARs into the project such that they are in the standard WEB-INF/lib directory?

Coraleecoralie answered 6/11, 2013 at 3:16 Comment(2)
Possible duplicate of #1052140Butterandeggs
Not really a duplicate. First of all, I am using version 12.1.6 and there is no such thing as Project Library -> Attach Jar. I see a little "+" sign at the bottom of that dialog which when clicked shows 3 choices: Jars or Directory, Library, Module Dependency. None of those is what I need, I don't think. Plus, I don't want these JARs to be "Project Jars". I need them to be module JARs and I need them to go together with the app when it's deployed. I choose add "Jars or Directory", but then it starts complaining that the JAR is missing from the Artifact.Coraleecoralie
P
14

In the Project Structure window, after adding the JAR in the section "Libraries", you can go to the section "Artifacts" and you'll see in the register "Output Layout" how the WEB-INF folder will look like. On the right side you see "Available Elements", which you can drag&drop to the left site into the lib folder.

Predate answered 20/11, 2014 at 12:55 Comment(0)
C
3

The only way i could do this is by adding the required jars manually to the WEB-INF/lib folder on the file system and add that to project library explicitly (apart from the way to add via module library as described in the linked SO question).

enter image description here

Hope that helps.

Curbing answered 23/6, 2014 at 15:52 Comment(0)
P
1

Create the WEB-INF folder manually in your project’s file system.

If you want the added jar(s) to be part your web app, part of your WAR file, then you may need to manually add the WEB-INF folder and nested lib folder to your file system if you do not already see them. Ditto if you want WEB-INF/classes to store anything such as Flyway database migration SQL scripts.

Once created, IntelliJ should auto-detect them and show in the project structure.

Even if you did not see these folders in your project structure, IntelliJ was likely creating them dynamically in packaging your web app at build-time. Anything you place in your manually created folders will be merged in alongside the other generated items being placed in the auto-generated WEB-INF folder. Not obvious at all, but an effective process.

Photokinesis answered 25/5, 2017 at 5:41 Comment(1)
Specially in IntelliJCymophane
I
0

Had exactly the same issue. In Intellij IDEA right click on WEB-INF/lib directory and choose "Add as Library..." Worked for me. Hope it helps!

Inclinatory answered 25/6, 2020 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.