简体   繁体   English

如何在具有依赖关系的Maven项目中添加专有库?

[英]How can add the proprietary library in maven project with dependency?

I have a proprietary library. 我有一个专有的图书馆。 I am using this library in my java desktop project but now, I have a maven project. 我在Java桌面项目中使用了这个库,但是现在,我有一个maven项目。 I want to add this library in my maven project with dependency. 我想将此库添加到我的Maven项目中并具有依赖关系。 How can I do this? 我怎样才能做到这一点?

Firstly you should search if this library is available as maven dependency. 首先,您应该搜索该库是否可用作maven依赖项。 Try maven search . 尝试进行Maven搜索

For example if you want to include a library commons-io-2.4.jar, you serach for it in the link above, if it is in public repository (it is), then you get maven dependency: 例如,如果您想包含一个库commons-io-2.4.jar,则可以在上面的链接中搜索它,如果它在公共存储库中(是),那么您将获得maven依赖项:

<dependency>
  <groupId>commons-io</groupId>
  <artifactId>commons-io</artifactId>
  <version>2.4</version>
</dependency>

You should paste this dependency to your pom to dependencies tag. 您应该将此依赖项粘贴到pom to依赖项标签中。

If above library is not available in public repository, you have to place your jar manually in your local repository by refering to: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html 如果上述库在公共存储库中不可用,则必须通过以下方式将jar手动放置在本地存储库中: http : //maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Example: 例:

mvn install:install-file -DgroupId=commons-io -DartifactId=commons-io -Dpackaging=jar -Dversion=2.4 -Dfile=home_folder_path/commons-io-2.4.jar -DgeneratePom=true

If it is not already on maven repository, simply add it to your pom.xml, and add it to your local repository. 如果尚未将其添加到maven存储库中,只需将其添加到pom.xml中,然后将其添加到本地存储库中即可。

<dependencies>
    <dependency>
        <groupId>com.proppath</groupId>
        <artifactId>mylib.jar</artifactId>
        <version>myjarversion</version>
    </dependency>

And also put this prop library into .m2\\repository\\com\\proppath\\myjarversion 并将此道具库放入.m2 \\ repository \\ com \\ proppath \\ myjarversion

Give any groupId you like but make sure that you have corresponding path on repository to find it. 提供您喜欢的任何groupId,但要确保您在存储库中具有相应的路径才能找到它。

Normally, in large projets these kind of propriatery libraries are stored in Nexus of your enterprise. 通常,在大型项目中,这类属性库存储在企业的Nexus中。

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

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