maven

scope

编译,测试,运行

  • 默认compile 打包的时候通常需要包含进去
  • test 仅参与测试相关的工作,包括测试代码的编译,执行
  • provided 不会将包打入本项目中,只是依赖过来,编译和测试时有效 (一般运行环境已经存在提供对应jar,项目不用)

  • system 也provided相同,不过被依赖项不会从maven仓库抓,而是从本地文件系统拿,一定需要配合systemPath属性使用。

添加本地jar

libs 直接包含包

不是从第三方仓库拉

项目根目录新建libs放入jar包

1
2
3
4
5
6
7
        <dependency>
            <groupId>com.tigergraph</groupId>
            <artifactId>tg-jdbc-driver</artifactId>
            <version>1.2</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/tg-jdbc-driver-1.2.jar</systemPath>
        </dependency>

Having a 3rd party jar included in Maven shaded jar without adding it to local repository

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!--add local jar-->
    <plugin>
        <groupId>com.googlecode.addjars-maven-plugin</groupId>
        <artifactId>addjars-maven-plugin</artifactId>
        <version>1.0.5</version>
        <executions>
            <execution>
                <goals>
                    <goal>add-jars</goal>
                </goals>
                <configuration>
                    <resources>
                        <resource>
                            <directory>${basedir}/libs</directory>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>

ide debug provided