maven引入本地的方法

jar包無法直接通過pom遠程倉庫下載,需要從自己本地引入的時候。

方法一

配置pom文件如下:將本地jar包引入工程,systemPath爲jar所在的本地路徑

        <dependency>
            <groupId>com.aliyun.vod</groupId>
            <artifactId>upload</artifactId>
            <version>1.4.14</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/aliyun-java-vod-upload-1.4.14.jar</systemPath>
        </dependency>

然後在build中加入打包資源

    <build>
        ....

        <resources>
            ....
            <resource>
                <directory>lib</directory>
                <targetPath>./BOOT-INF/lib/</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
        </resources>
    </build>

這樣通過maven打包的時候會打到對應的目錄,但是在打包時會有警告,不影響使用

 方法二

修改pom文件

        <dependency>
            <groupId>com.aliyun.vod</groupId>
            <artifactId>upload</artifactId>
            <version>1.4.14</version>
        </dependency>

引入插件

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
                <executions>
                    <execution>
                        <id>install-upload</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${project.basedir}/lib/aliyun-java-vod-upload-1.4.14.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>com.aliyun.vod</groupId>
                            <artifactId>upload</artifactId>
                            <version>1.4.14</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

<phase>clean</phase> 表示該 jar 包會在執行 clean 操作時引入,這樣就會把這個安裝到本地倉庫中,所以也就能夠在pom直接使用了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章