简体   繁体   English

使用本地jar作为Maven依赖插件中的工件?

[英]Use local jar as artifact in maven dependency plugin?

We have a maven project in which we use some artifacts that are not present in any remote repositories. 我们有一个Maven项目,其中我们使用了一些远程存储库中不存在的工件。 They are included in our project in some directory, say /lib, as compiled .jar files. 它们作为已编译的.jar文件包含在我们项目的某个目录(例如/ lib)中。 Some of these are "plain" dependencies which we can utilize from /lib using scope system + systemPath, however there is one artifact that should be used with the maven-dependency-plugin unpack goal. 其中一些是“普通”依赖项,我们可以使用范围系统+ systemPath在/ lib中使用,但是应该将一个工件与maven-dependency-plugin拆包目标一起使用。 The relevant part of the pom.xml looks like this pom.xml的相关部分如下所示

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-dependency-plugin</artifactId>
   <executions>
       <execution>
           <id>unpack-resources</id>
           <phase>generate-resources</phase>
           <goals>
               <goal>unpack</goal>
           </goals>
           <configuration>
               <artifactItems>
                   <artifactItem>
                       <groupId>xxx.yyy.zzz</groupId>
                       <artifactId>ourartifact</artifactId>
                       <outputDirectory>${target.directory}/somedir</outputDirectory>
                       <includes>
                           files1/**,files2/**,files3/**
                       </includes>
                   </artifactItem>
               </artifactItems>
           </configuration>
       </execution>
   </executions>
</plugin>

However this still tries to reach out to the remote repository and fetch the artifact from there, which of course does not succeed. 但是,这仍然尝试到达远程存储库并从那里获取工件,这当然不会成功。 Can we somehow achieve that this artifact is also attempted to be fetched from /lib? 我们能否以某种方式实现也尝试从/ lib提取此工件的情况?

Instead of fetching from /lib, and if setting up your own Nexus/Artifactory/etc... is a bit much right now, you could add the jar to your local repository. 与其从/ lib中获取数据,不如现在设置自己的Nexus / Artifactory / etc ...,您可以将jar添加到本地存储库中。 Each individual would have to do this on their own computer, but once there, it would be available to all the maven built projects on that machine, so you wouldn't have to have a /lib copy for each project. 每个人都必须在自己的计算机上执行此操作,但是一旦到达该位置,该计算机上的所有Maven构建项目都可以使用它,因此您不必为每个项目都拥有/ lib副本。 If you are compiling that jar yourself and it is a maven project, you can do "mvn install" and that will install to your local repo. 如果您自己编译该jar,并且它是一个Maven项目,则可以执行“ mvn install”,它将安装到本地存储库中。 Note that mvn package won't install to your local repo. 请注意,mvn软件包不会安装到您的本地存储库中。

If this is a 3rd party jar, you can use mvn install:install-file to do this. 如果这是第3方jar,则可以使用mvn install:install-file来执行此操作。 To do this, follow the instructions at https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html . 为此,请按照https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html上的说明进行操作。

Hope this helps! 希望这可以帮助!

Update: by local repository, I might mean differently than you referred to in your comment -- I mean the local repository on each user's computer, versus a repository server that is local to your intranet. 更新:通过本地存储库,我的意思可能与您在注释中提到的含义有所不同-我的意思是每个用户计算机上的本地存储库,而不是Intranet本地的存储库服务器。 Sorry if that caused any confusion :) 对不起,如果引起任何混乱:)

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

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