既使用maven又使用本地Jar包

maven 使用本地包 lib jar包 依赖一个lib目录

解决方法:

1. 把本地的lib加入maven编译时的依赖路径

     如下配置:

1
2
3
4
5
6
7
8
9
10
11
<plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
             <source>1.6</source>
             <target>1.6</target>
             <encoding>UTF-8</encoding>
             <compilerArguments>
              <extdirs>lib/</extdirs>
            </compilerArguments>
         </configuration>
       </plugin>

  

2. 本地system 配置

   这种的不好处是,只能加入某个jar包而不是某个目录

1
2
3
4
5
6
7
<dependency>
    <groupId>org.swinglabs</groupId>
    <artifactId>swingx</artifactId>
    <version>0.9.2</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/swingx-0.9.3.jar</systemPath>
</dependency>

  

3. 把jar包安装入本地仓库

  - 先安装jar包到本地仓库

  - 引用安装的jar包

      注意: 正规maven的方法,要求jar包中有合法的 artifactId信息

1
2
3
4
5
6
7
8
9
10
11
<repository>
    <id>repo</id>
    <releases>
        <enabled>true</enabled>
        <checksumPolicy>ignore</checksumPolicy>
    </releases>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <url>file://${project.basedir}/repo</url>
</repository>

4. 使用install  插件  (推荐使用)

     配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install-external</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${basedir}/lib/app-0.0.1.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>com.dalong.locallib</groupId>
                            <artifactId>appbanner</artifactId>
                            <version>0.0.1</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

  

     

5. 使用命令

   

1
mvn install:install-file  -Dfile=D:/jar/xxx.jar  -DgroupId=xxx.xxx  -DartifactId=xxx -Dversion=x.x -Dpackaging=jar

  

 

     

posted on   荣锋亮  阅读(9631)  评论(0编辑  收藏  举报

编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· spring官宣接入deepseek,真的太香了~

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示