Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove jar from Maven Dependencies in eclipse

Tags:

maven

I am trying to get rid of a jar from my Maven Dependencies folder which is automatically generated in eclipse. As this folder is not editable, I tried deleting the corresponding jar manually from .m2/repository and also removed the jar from my pom file and refreshed eclipse project. But no impact. Jar continues to stay in dependencies folder in eclipse. Then, I re-started my laptop. now jar is re-populated in .m2/repository and of course its in maven dependencies folder in eclipse as well. any suggestions.

like image 693
IphoneDev Avatar asked Sep 29 '11 19:09

IphoneDev


People also ask

How do I remove a jar from an m2 repository?

If you want to explicitly remove a single artifact from the cache, use purge-local-repository with the manualInclude parameter. For example, from the command line: mvn dependency:purge-local-repository -DmanualInclude="groupId:artifactId, ..."

How do I add a missing jar to Maven dependencies in Eclipse?

You can find this in Window > Preferences > Maven > User Settings , and then point Global Settings to your external maven settings. xml . Then i removed the broken projects and re-added them, and the Maven Dependencies library appeared again. Save this answer.

Are Maven dependencies included in jar?

Apache Maven Shade Plugin provides the capability to package the artifact in an uber-jar, which consists of all dependencies required to run the project.


1 Answers

If the jar is a dependency of another library you have included in your POM then you may have to exclude that library in the POM. The spring framework must have some kind of logging but if you do not want to use apache commons logging and would rather use something else you must exclude the offending library:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

commons-logging-1.1.1.jar will nolonger litter my maven dependencies.

One thing to note is that you must exclude it from every dependency that requires it (e.g. if you have spring-context and spring-core in your pom you must put the <exclusions> section in each <dependency></dependency>).

Eclipse m2 plugin has a nifty little extension that allows you to right click on the jar then select Maven -> Exclude Maven artifact...

like image 63
tribeca Avatar answered Sep 20 '22 05:09

tribeca