如何将本地jar文件添加到maven项目?


如何直接在我的项目的库源代码中添加本地jar文件(不是Maven仓库的一部分)?

按照以下步骤将JAR安装到本地Maven仓库中:

mvn install:install-file
   -Dfile=<path-to-file>
   -DgroupId=<group-id>
   -DartifactId=<artifact-id>
   -Dversion=<version>
   -Dpackaging=<packaging>
   -DgeneratePom=true

Where: <path-to-file>  the path to the file to load
   <group-id>      the group that the file should be registered under
   <artifact-id>   the artifact name for the file
   <version>       the version of the file
   <packaging>     the packaging of the file e.g. jar

参考

您可以直接添加本地依赖项(如构建包含propriatery库的maven项目)如下所示:

<dependency>
    <groupId>sample</groupId>
    <artifactId>com.sample</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>

未经作者同意,本文严禁转载,违者必究!