当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to instruct maven to automatically add dependency jars when they include a artifact that i created?

问题描述:

Well i have reusable code which i developed using Maven and the result artifact is a JAR.

Now to use it in another project , i have simply added the this dependency to that project's POM.xml,

but maven is not auto detecting and including the dependencies for the jar.

How do i go about do this ?

Appreciate any pointers in this regard .

网友答案:

You should try to build the developed(reusable) code with dependencies. I'm not quite sure if this will help (I had some issues with the build with dependencies, too), but I think it's worth a try. So you should add this to the pom.xml (of the reusable project):

  <build>
  ...
     <plugins>
  ...
        <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-jar-plugin</artifactId>
           <configuration>
              <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>fully.qualified.MainClass</mainClass>
                </manifest>
              </archive>
           </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
              <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>
            </configuration>
         </plugin>
    </plugins>
   </build>

For details, have a look at this question and the maven-documenation

网友答案:

I solved this by manually adding the pom file for the jar I created.

[file structure]

GroupIdFolder

ArtifactIdFolder

VersionFolder

ownjar.jar [artifact I created]
ownjar.pom [file I mannually created]

Then in the .pom file put in the dependencies.

<project>
    <dependencies>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
        </dependency>
    </dependencies>
</project>
分享给朋友:
您可能感兴趣的文章:
随机阅读: