配置本地maven仓库

云端maven仓库不方便配置的话,在本地配置也是个不错的选择,方便管理与移植。

步骤

  1. 下载个maven文件,比如apache-maven-3.9.3-bin.zip
  2. 解压到电脑本地
  3. 编辑apache-maven-3.9.3/conf/settings.xml文件,修改如下:
# xxx路径改成自己本地的
<localRepository>xxx\apache-maven-3.9.3\repository</localRepository>

使用

比如,IntelliJ IDEA,设置-》搜索maven

User settings file:xxx\apache-maven-3.9.3\conf\settings.xml
Local respository:xxx\apache-maven-3.9.3\repository

三方jar放到本地maven仓库

  1. 执行以下命令,把jar放到仓库内
# 示例
mvn install:install-file -Dfile=C:Users\xxx\xxx.jar -DgroupId=com.my.groupId -DartifactId=my.artifacetId -Dversion=1.0.0 -Dpackaging=jar

命令说明

-Dfile:jar路径
-DgroupId:自定义groupId
-DartifactId:自定义artifactId
-Dversion:自定义版本
-Dpackaging:默认jar

执行成功,如截图


image.png
  1. 使用,比如,pom.xml引用
<dependency>
    <groupId>com.my.groupId</groupId>
    <artifactId>my.artifacetId</artifactId>
    <version>1.0.0</version>
</dependency>

把三方jar打到war包中

通过以下配置

<build>
    <finalName>xxx</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <version>3.6.1</version>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <compilerArguments>
                    <extdirs>C:\Users\xxx\libs</extdirs><!--指定外部lib-->
                </compilerArguments>
            </configuration>
        </plugin>
    </plugins>
</build>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容