maven使用本地jar包并将jar包打包进项目

在maven项目中因为一些特殊原因找不到某个jar的仓库,但是有该jar文件,新建lib文件夹,并将jar文件放到lib文件夹内,然后在pom文件中加入依赖:

        <dependency>
            <groupId>com.xxxx</groupId>
            <artifactId>xxx-yyy</artifactId>
            <version>1.0.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/xxx.jar</systemPath>
        </dependency>

这样就可以加载本地jar到项目中去了,可以使用jar包内容并编译通过,但是通过maven打包时会提示xxx.jar不存在。这是在编译插件中再加入配置参数:

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <extdirs>${project.basedir}/lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>

其实主要的配置为

                    <compilerArguments>
                        <extdirs>${project.basedir}/lib</extdirs>
                    </compilerArguments>

${project.basedir}为maven的内置变量,是项目路径,而lib则是我放jar包的文件夹。

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