1

I've followed the tutorial at https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/, to successfully create a WAR file. However, I also need an external jar library, which I, at the moment, manually put in the resulting WAR file, inside the folder WEB-INF/lib.

What I want is to put all the external jars in say a folder lib,and have Maven automatically place them in the WEB-INF/lib folder of resulting WAR file, during compilation. How can I do that?

MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
  • 1
    I voted to close as a duplicate. There are several answers in there, the best one is this one which is unfortunately not the accepted answer: https://stackoverflow.com/a/28762617/424903 – Gimby Apr 30 '19 at 15:02

1 Answers1

3

Maven will automatically add dependencies to WEB-INF/lib which their scope should be compile. So If you want to put external jars its just enough to put a maven dependency to that external jar with the scope of compile which is the default one. For more information look at this question

Mohsen
  • 4,536
  • 2
  • 27
  • 49
  • Addendum: When coming from C this might be not obvious, but Maven always handles artifacts (jars) through GAVs (GroupId, ArtifactId, Version), not through paths or files. These GAVs are resolved against (local and remote) Maven repositories. – J Fabian Meier Apr 30 '19 at 14:47
  • @JFMeier Yes, that is what I am wondering. How to do it without specifying groupId, artifactId et al. – MetallicPriest Apr 30 '19 at 14:49
  • 2
    You don't. Actually, there are ways around it (see @DKAnsh answer), but they are not really recommended. If you do Maven, you put your artifacts into a Maven repository and reference them by Maven coordinates. What is the problem with that? – J Fabian Meier Apr 30 '19 at 14:52