Maven: How to include jars in Eclipse, which are not available in repository?

前端 未结 5 1463
自闭症患者
自闭症患者 2020-12-16 16:40

I have copied the JARs into src\\main\\webapp\\WEB-INF\\lib.
I use eclipse. If I add the jars one-by-one to Project-> Java Build Path-> Add jars, then I do

5条回答
  •  粉色の甜心
    2020-12-16 17:02

    There are atleast three approaches in which 3rd party JARs can be added to Maven projects.

    1. Install manually using mvn install command
    2. Adding the location of jar file in pom dependency with the the following tag system
    3. Creating a 'dummy' maven repository pointing to jar location.

    While approach 1 and 2 has been suggested above, I will focus on third approach which I find more cleaner and does not require any mvn command and works out of box from any IDE.

    Step 1: Add the location of local 'dummy' repository in pom.xml

    
        
            repo
            repo
            file:${project.basedir}/src/main/resources/lib
        
    
    

    Here the 'dummy' repository location is the 'lib' folder of my project directory

    Step 2 : Add the jar dependency into your pom.xml

        
            com.cloudera.impala
            impala-frontend
            0.1-SNAPSHOT
        
    

    choose any groupId but make sure that artifactId and version is of the format -.jar ( Name of 3rd party jar)

    Step 3 : Create the folder structure as per the groupId,artifactId and version mentioned in the Step 2 in your local 'dummy' repository. So in this case the folder struction would be /src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/

    Place your jar in the version folder and build your project. You will get the following output which treats your 'dummy' repository to be the provider of your 3rd party jar.

    [INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/maven-metadata.xml
    [INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.pom
    [WARNING] The POM for com.cloudera.impala:impala-frontend:jar:0.1-SNAPSHOT is missing, no dependency information available
    [INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
    [WARNING] Could not validate integrity of download from file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar: Checksum validation failed, no checksums available
    [WARNING] Checksum validation failed, no checksums available from repo for file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
    [INFO] Downloaded from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar (7.0 MB at 79 MB/s)
    [INFO] 
    
    

提交回复
热议问题