maven加载外部依赖包

并非全部的jar包都能在maven仓库下载,另外有些场景也很差使用私有仓库,那么这种状况下,如何把这些外部的jar也经过maven管理起来呢。apache

使用maven-install-plugin

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
            </plugin>

实例

在maven工程根目录新建lib文件夹,里头有个demo.jar归入管理maven

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

安装code

mvn clean install

添加依赖get

<dependency>
            <groupId>com.example</groupId>
            <artifactId>demojar</artifactId>
            <version>1.0.0</version>
        </dependency>

这样就大功告成了,能够打成fat jarit

doc

相关文章
相关标签/搜索