JAVA_CAT
JAVA_CAT

Reputation: 859

How to remove unwanted jars included in the lib using maven

I am using viewservlets.jar file in my application. I added the following dependency in my pom.xml.

<dependency>
            <groupId>org.eclipse.birt.runtime</groupId>
            <artifactId>viewservlets</artifactId>
            <version>4.4.1</version>
        </dependency>

After packaging I could see birt runtime jar also in my lib. Similarly many other jars. I am not sure how all these jars included in my folder. I am using java 8. Still I can see some jars related to jdk14 (e.g bcmail-jdk14-1.38.jar , bcprov-jdk14-1.38.jar ) . That is also multiple times. The war files are getting big because of this.

Update

In the runtime package there are many other packages can be found. If i count it is more than 30 nos. In this i need only one jar file. So is there any way to include only one jar instead of using exclusion for the remaining 30+ entry?

Upvotes: 0

Views: 1045

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35853

Maven automatically resolves dependencies transitively, i.e. it adds the dependencies of your dependencies to the WAR as well.

This way Maven makes sure that you do not run into ClassNotFound exceptions because viewservlets is trying to call something that does not exist.

Of course, it may be the case that some of those dependencies are not really called at runtime. If you are sure that a given artifact is never called, you can exclude it with an exclusion. But it is generally hard to determine that and it is probably not worth the effort.

EDIT: an example

<dependency>
  <groupId>org.eclipse.birt.runtime</groupId>
  <artifactId>viewservlets</artifactId>
  <version>4.4.1</version>
  <exclusions>
     <exclusion>
        <groupId>*</groupId>
        <artifactId>*</artifactId>
     </exclusion>
   </exclusions>
</dependency>
<dependency>
  <groupId>org.something</groupId>
  <artifactId>otherdependency</artifactId>
  <version>1.2.3</version>
</dependency>

Upvotes: 1

Related Questions