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包的文件夾。

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