简体   繁体   English

Maven和引用库

[英]Maven and Referenced Libraries

I have a eclipse java project. 我有一个Eclipse Java项目。 It has external jar in Referenced Libraries. 它在参考库中有外部jar。 I want to use Maven. 我想使用Maven。 But I would like to know how to include this external jar in Maven. 但是我想知道如何在Maven中包含这个外部jar。 Is it necessary a repository? 是否需要存储库?

Just check out the maven repository http://mvnrepository.com/ 只需查看Maven存储库http://mvnrepository.com/

Then in the Pom dependencies file you will need to add whichever dependencies you find that you will need following the xml format. 然后,在Pom依赖文件中,您将需要添加发现的所有依赖XML格式的依赖。 Then run mvn package to download the updated dependencies. 然后运行mvn包以下载更新的依赖项。

<project xmlns="http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
   http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.companyname.bank</groupId>
   <artifactId>consumerBanking</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>consumerBanking</name>
   <url>http://maven.apache.org</url>

   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>

      <dependency>
         <groupId>ldapjdk</groupId>
         <artifactId>ldapjdk</artifactId>
         <scope>system</scope>
         <version>1.0</version>
         <systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath>
      </dependency>
   </dependencies>

</project>

If I understood your question, you have a external jar your eclipse project references, but you want to refer to the jar using Maven. 如果我理解您的问题,那么您的eclipse项目引用中有一个外部jar,但是您想使用Maven来引用jar。

The details of the Jar are not clear, so look to see if the jar is hosted in some public repo. Jar的详细信息尚不清楚,因此请查看该jar是否托管在某个公共仓库中。

You can also install the jar in your local repository : 您也可以将jar安装在本地存储库中:

mvn install:install-file -Dfile=/path/to/jar/abc.jar -DgroupId=group -DartifactId=artifactid -Dversion=1 -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=/path/to/local/repository

Make sure you replace the values for the file, group, artifactid, version and local repository path. 确保替换文件,组,artifactid,版本和本地存储库路径的值。

Then it is only a matter of including this like any other jar in your dependency section in your POM 然后,只需像在您的POM的依赖项部分中那样包含其他jar一样,就可以了

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

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