简体   繁体   中英

Maven - Load jar contained in dependency

I'm new to maven and I know that this is a common problem but can't make my project work.

I have an jar A which contains only a manifest and a lib folder with a jar B.

I'm able to add A as dependency in this way:

<dependency>
    <groupId>A</groupId>
    <artifactId>A</artifactId>
    <version>1.0.0</version>
    <scope>compile</compile>
</dependency>

Maven successfully builds but at runtime I get a ClassNotFoundException for a class contained in B.

So, how can I include B?

My plugins section is like this:

<plugins>

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

</plugins>

IMHO you should create two project A and B. Having module BI would install it in local Maven repo (mvn install) and the pull it like regular Maven dependency.

Probably your IDE see B's classes as you have jar in lib folder.

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