简体   繁体   English

如何使用Maven添加外部jar库,并可能遵循完整的(内部带有外部jar)包装?

[英]How to add external jar library with Maven, with the possibility of following full(with external jar inside) packaging?

I use Maven and have external library(soot). 我使用Maven并具有外部库(soot)。 I want to add this library to my project with Maven, and then package into 1 uber jar. 我想使用Maven将这个库添加到我的项目中,然后打包到1个uber jar中。

1)To add library, i can use local repo( example ). 1)要添加库,我可以使用本地回购( 示例 )。

2)To get a jar with dependencies, i can use shade-plugin or other. 2)要获得具有依赖关系的罐子,我可以使用阴影插件或其他。

But together it isn't work, because on first step dependency have scope , and this dependency will not be added to uber jar. 但是总的来说这是行不通的,因为在第一步,依赖项具有scope,并且此依赖项不会添加到uber jar中。

I understand that i can do mvn install, but it will work only on my machine. 我了解我可以进行mvn安装,但是它只能在我的机器上工作。

Is it possible to achieve my initial goal? 是否有可能实现我的最初目标?

Maybe the simplest solution for you would be to use your local (company?) repository like Artifactory . 对于您来说,最简单的解决方案可能是使用您的本地(公司)存储库,例如Artifactory

However if it is not possible, you can use local in-project repository (as from your example ) and keep it in your vcs. 但是,如果不可能,则可以使用本地项目内存储库(如您的示例所示 ),并将其保存在vcs中。

<repository>
    <id>in-project</id>
    <name>In Project Repo</name>
    <url>file://${project.basedir}/libs</url>
</repository>

The only trick is how to get artifacts (jars) to that local repository: 唯一的技巧是如何将工件(jar)放入该本地存储库:

mvn deploy:deploy-file -Dfile=fooLib.jar  -DgroupId=com.test -DartifactId=fooLib -Dversion=1.0.1 -Dpackaging=jar -Durl=file://pathTo/libRepo -DrepositoryId=in-project

And you just use it as any other dependency 而且您可以将其用作任何其他依赖项

<dependency>
        <groupId>com.test</groupId>
        <artifactId>fooLib</artifactId>
        <version>1.0.1</version>
</dependency>

Definitely don't use system scope , since such dependencies are expected to be found in system and therefore are not bundled with JAR. 绝对不要使用system 范围 ,因为此类依赖项应该在系统中找到,因此不会与JAR捆绑在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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