简体   繁体   中英

Maven : Copy only selected jars inside WEB-INF/lib

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!

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM