0

In my Maven project , I have certain dependencies which should be present inside the WEB-INF/lib . I cannot put all the jars inside WEB-INF/lib , only the selected ones . How to go about doing this?

I cannot use the maven-resources plugin since then I would have to mention the entire jar's name inside <include> tag and I need to keep it dynamic.

I tried using <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes> but this not give me an option to insert only selected jars inside the lib folder.

I also tried using <scope>provided</scope> for some of the jars but due to this the name of the jar doesn't get added to the classpath field inside manifest.mf file.

Please suggest some solution. Thanks in advance!

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Akhil Nambiar
  • 315
  • 3
  • 18
  • 2
    by telling us why you need this we might be able to give you alternative ways of getting it done with Maven you might not have thought of. Generally my experience with Maven is that if I need a task done a certain way and that way seems overly complicated I take it as a hint i'm on the wrong path and need to rethink either the how of the task or sometimes the task's existence itself. – Newtopian Dec 07 '15 at 14:08
  • *"I also tried using provided for some of the jars but due to this the name of the jar doesn't get added to the classpath field inside manifest.mf file"* ... is that strange? If it would do that then it would be adding jars which do not exist. What setup do you have that you need non-existent jars in the manifest.mf ? – Gimby Dec 07 '15 at 14:43
  • Actually , I need even those jars in the manifest which have the scope provided . Can you help me with the same? – Akhil Nambiar Dec 08 '15 at 05:33

2 Answers2

0

You can use Assembly plugin and customized assembly descriptor. In descriptor you can set which jars you want to copy with their artifact id, group id, version and scope. it also supports regex. https://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html

Rahim Dastar
  • 1,259
  • 1
  • 9
  • 15
0

This may not be the best way to package the content for the WEB-INF/lib/ nested directory in a WAR file, but the implementation presented in the question for How to put all required jars in a lib folder inside the final jar with maven (using the maven-dependency-plugin plugin) solved my JAR needs for bundling all dependent jars into the lib/ directory of my final jar. Oddly it's a commonly asked question, with many different solutions. This implementation actually bundled the jars inside the nested lib/ directory, while others, for example, extracted the contents of my dependent jars and laid their classes beside my classes. So this might get you a little closer but probably not the official way of handling a WAR files' library deps.

Community
  • 1
  • 1
dan
  • 741
  • 9
  • 14