How to add local jar files to a Maven project?

后端 未结 30 3329
悲&欢浪女
悲&欢浪女 2020-11-21 04:58

How do I add local jar files (not yet part of the Maven repository) directly in my project\'s library sources?

30条回答
  •  再見小時候
    2020-11-21 05:22

    Step 1: Configure the maven-install-plugin with the goal install-file in your pom.xml

    
        org.apache.maven.plugins
        maven-install-plugin
        
            
                install-external-non-maven-jar-MWS-Client-into-local-maven-repo
                clean
                
                    default
                    com.amazonservices.mws
                    mws-client
                    1.0
                    ${project.basedir}/lib/MWSClientJavaRuntime-1.0.jar
                    jar
                    true
                
                
                    install-file
                
            
        
    
    

    Make sure to edit the file path based on your actual file path (recommended is to place these external non-maven jars inside some folder, let's say lib, and place this lib folder inside your project so as to use project-specific relative path and avoid adding system specific absolute path.

    If you have multiple external jars, just repeat the for other jars within the same maven-install-plugin.

    Step 2: Once you have configured the maven-install-plugin as shown above in your pom.xml file, you have to use these jars in your pom.xml as usual:

        
            com.amazonservices.mws
            mws-client
            1.0
        
    

    Note that the maven-install-plugin only copies your external jars to your local .m2 maven repository. That's it. It doesn't automatically include these jars as maven dependencies to your project.

    It's a minor point, but sometimes easy to miss.

提交回复
热议问题