|
Maven 引入外部依赖 如果我们需要引入第三库文件到项目,该怎么操作呢?
pom.xml 的 dependencies 列表列出了我们的项目需要构建的所有外部依赖项。
要添加依赖项,我们一般是先在 src 文件夹下添加 lib 文件夹,然后将你工程需要的 jar 文件复制到 lib 文件夹下。我们使用的是 ldapjdk.jar ,它是为 LDAP 操作的一个帮助库:

然后添加以下依赖到 pom.xml 文件中:
< dependencies >
<!-- 在这里添加你的依赖 -->
< dependency >
< groupId > ldapjdk </ groupId > <!-- 库名称,也可以自定义 -->
< artifactId > ldapjdk </ artifactId > <!-- 库名称,也可以自定义 -->
< version > 1.0 </ version > <!-- 版本号 -->
< scope > system </ scope > <!-- 作用域 -->
< systemPath > ${basedir}\src\lib\ldapjdk.jar </ systemPath > <!-- 项目根目录下的lib文件夹下 -->
</ dependency >
</ dependencies >
pom.xml 文件完整代码如下:
< project xmlns = " http://maven.apache.org/POM/4.0.0 "
xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation = " http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd " >
< modelVersion > 4.0.0 </ modelVersion >
< groupId > com.companyname.bank </ groupId >
< artifactId > consumerBanking </ artifactId >
< packaging > jar </ packaging >
< version > 1.0-SNAPSHOT </ version >
< name > consumerBanking </ name >
< url > http://maven.apache.org </ url >
< dependencies >
< dependency >
< groupId > junit </ groupId >
< artifactId > junit </ artifactId >
< version > 3.8.1 </ version >
< scope > test </ scope >
</ dependency >
< dependency >
< groupId > ldapjdk </ groupId >
< artifactId > ldapjdk </ artifactId >
< scope > system </ scope >
< version > 1.0 </ version >
< systemPath > ${basedir}\src\lib\ldapjdk.jar </ systemPath >
</ dependency >
</ dependencies >
</ project > |
程序猿的技术大观园:www.javathinker.net
[这个贴子最后由 flybird 在 2020-02-12 11:45:58 重新编辑]
|
|