简体   繁体   English

Maven:通过项目目录外的相对路径向jar添加依赖项

[英]Maven: add a dependency to a jar by relative path outside the project directory

The situation is largely similar as in this SO question except for the resource I'm trying to point to is outside the project folder. 除了我要指向的资源不在项目文件夹之外,情况与此SO问题基本相似。

The background is that I have a git repo that contains a few projects. 背景是我有一个git repo,其中包含一些项目。 One of the projects requires a jar from another project for running so the intended dependency should be smth like this: 其中一个项目需要另一个项目的jar才能运行,因此预期的依赖项应如下所示:

<dependency>
    <groupId>another-proj-jar</groupId>
    <artifactId>another-proj-jar</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>../another-proj/build/another-proj.jar</systemPath>
</dependency> 

another-proj is not a Maven project (and converting it to a Maven proj is an issue of itself, let's skip it here) so I create that jar manually through Eclipse import. another-proj不是Maven项目(将其转换为Maven proj本身就是一个问题,让我们在此处跳过),因此我通过Eclipse导入手动创建了该jar。

However, I am not sure whether it is possible to indicate a relative path beyond the project directory because all examples point to //${basedir}/my-repo where ${basedir} is essentially the current project folder. 但是,我不确定是否可以指示项目目录之外的相对路径,因为所有示例都指向//${basedir}/my-repo ,其中${basedir}本质上是当前项目文件夹。 I need to make it one level up the current project's folder. 我需要将其升级到当前项目的文件夹。

Could you tell me whether it's possible and how or what could be a workaround? 您能告诉我是否可行,如何解决?

Really this should just be a normal dependency. 确实,这应该只是正常的依赖关系。 In the project you are dependent on (another-proj in your example) run a mvn clean install . 在您依赖的项目中(示例中的另一个项目)运行mvn clean install This will copy the .jar file to your ~/.m2/repository directory. 这会将.jar文件复制到您的~/.m2/repository目录。 Then in the project that requires the library have a dependency like: 然后在需要库的项目中有一个依赖项,例如:

<dependency>
    <groupId>another-proj-jar</groupId>
    <artifactId>another-proj-jar</artifactId>
    <version>1.0-SNAPSHOT</version>  <!-- or whatever it is set to -->
</dependency> 

The huge advantage with this is that if the jar you're pulling in requires anything else then that'll get pulled in too. 这样做的巨大好处是,如果您要拉入的罐子需要其他任何东西,那也将被拉入。

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

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