Configure Maven so that it uses jars for compilation but excludes them while bundling into war file

I got a requirement to customize our projects using Maven. We have 3 projects based on Spring & Hibernate. Hence, there are repeated jars in each WAR file while building, which increases size unnecessarily while deployment.

So we have decided to keep all jar dependencies into one project called "CommonJars" and other existing projects will use them. For deployment, we want to generate TAR/ZIP file of "CommonJars" (while deploying it should be extracted in folder, most probably lib folder of Tomcat as it is common to the projects deployed in webapps folder) and other WAR file without jars. So that we can reduce the size of WAR files of 3 projects.

Can somebody suggest me on how we can achieve this? As I am new to Maven, I am unable to find proper solution for this.

Upvotes: 0

Views: 65

Answers (1)

JC Carrillo
JC Carrillo

Reputation: 1026

I do not agree with your approach but to solve your maven issue, you need to include a 'scope' in your maven dependency.

Example:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.0.1.Final</version>
    <scope>provided</scope>
</dependency>

The Maven Scope 'provided' will allow you to compile your projects but maven will not include them in your war.

Good luck.

Upvotes: 4

Related Questions