IphoneDev
IphoneDev

Reputation: 129

how to remove jar from Maven Dependencies in eclipse

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.

Upvotes: 10

Views: 43184

Answers (2)

user3176558
user3176558

Reputation: 39

I have the same problem and figured out how to do it.

  • If you are not using that JAR file, you can:

    1. Right-click on the project
    2. Choose [delete]
    3. Do NOT check "Delete project contents on disk"
    4. Click OK
    5. Wait for it to complete
    6. Import your project to your workspace again (Existing Maven Projects) Now the unused JAR files are gone.
  • If you are using (part of) that JAR file, you can do as tribeca said.

Upvotes: 1

tribeca
tribeca

Reputation: 462

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...

Upvotes: 8

Related Questions