简体   繁体   中英

Third party jar depending on other third party jars

I want to use a third party jar, let's call it Third.jar. This Third.jar file is in a directory A/. In A/lib/ there are more jars (let's say from party X, and party Y). When I use maven-install-plugin, I only make available the Third.jar in the local Maven repository, but when I then try to run it it will fail, because it cannot find classes contained in those party X, and party Y jars.

Since I am not supposed to care about the internal dependencies of Third.jar, how is this supposed to be solved with Apache Maven 3.3.3?

You need not care for internal dependencies for a jar if you can only find it in maven repository , because maven takes care of this for you. But if you are adding a third party jar to your local repository using maven-install-plugin , you are the only one who should take care of the internal dependencies of the added jar. Which means you would need to use maven-install-plugin and add party X and party Y jars in your local repo and add them in pom.xml along with Third.jar

Unless you know you don't need a dependency, you have to assume you need them all.

If you need to save space, you can drop a dependency you know you are not using, however in general this is time consuming and error prone and I would avoid doing this.

If you really sure that you don't want other jars and your application doesn't break then you can specify exclusions in your pom.xml dependencies like this.

<dependency>
    <groupId>YourGroup</groupId>
        <artifactId>Third</artifactId>
        <version>version</version> 
    <exclusions>
    <exclusion>
        <groupId>XGroup</groupId>
        <artifactId>X</artifactId>
    </exclusion>
    <exclusion>
        <groupId>YGroup</groupId>
        <artifactId>Y</artifactId>
    </exclusion>
  </exclusions>
</dependency>

If the other jars are not added in your local repository then remove those other dependencies in pom.xml of third maven repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM