简体   繁体   中英

Maven and Referenced Libraries

I have a eclipse java project. It has external jar in Referenced Libraries. I want to use Maven. But I would like to know how to include this external jar in Maven. Is it necessary a repository?

Just check out the maven repository 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. Then run mvn package to download the updated dependencies.

<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.

The details of the Jar are not clear, so look to see if the jar is hosted in some public repo.

You can also install the jar in your local repository :

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.

Then it is only a matter of including this like any other jar in your dependency section in your POM

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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