开发者

Maven: My project has a dependency that is NOT in any maven repo (system scope). Does it get included in my final jar?

So my maven project depends on a jar that is NOT in any maven repository. Therefore I need to use the system scope to include this local file in my maven classpath. Question is: When I build my final jar to distribute my library, I do need to somehow include that dependency with it. The classes can be extracted and then bundled with my library classes OR the jar can be included somehow inside my library jar. I am not even sure 开发者_开发技巧the latter (jar inside jar) is possible in Java.

So how should I approach this problem? Will Maven take my system scope dependency and take care of that for me? What should I do?

Thanks!


No, it will not. These dependencies are only for compilation and transitive dependency resolution. Your library consumers should have the jar too. However, you could use the Assembly Plugin to repackage the jar's classes into your artifact.

Or, the standard approach: then you will publish your artifact, you will create a public repository for deployment. You also could deploy the jar in it.

UDPATE: adding example for the shade plugin (instead of the Assembly)

  <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.4</version>
        <executions>
          <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <artifactSet>
                        <includes>
                          <include>legacy-jar.groupId:legacyJar</include>
                        </includes>
                  </artifactSet>
                </configuration>
          </execution>
        </executions>
  </plugin>


There is a second option. Put the jar into your repository as described here:

http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

and to your online repository

http://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html

give your client access to your repository and use your legacy.jar as normal dependency.

It depends a little bit what kind of library do you have. With this way you don't have problems with version conflicts of your legacy.jar in the environment of your customer.


Could this be what you are looking for, http://maven.40175.n5.nabble.com/How-to-specify-local-dependency-in-maven2-td103415.html.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜