将自己开发的依赖包加入到Maven本地仓库

Maven 在 pom 文件中加入自己开发的依赖包,这些包肯定是不在Maven仓库()的。那我们怎么将那些不在Maven仓库中的包加入到本地的Maven库中呢?很简单。这里以IKAnalyzer.jar包为例进行讲解。

第一步 :将IKAnalyzer.jar包存放在一个文件夹中,比如test文件夹
第二步 :建一个IKAnalyzer.jar包相关的 pom .xml文件,需要在pom.xml中定义其maven坐标及其相应的依赖代码即可,同样将pom文件存放在上述jar文件同一文件夹下,IKAnalyzer.jar坐标及依赖代码如下:

<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 ">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.wltea.ik-analyzer</groupId>
  <artifactId>ik-analyzer</artifactId>
  <version>3.2.8</version>
  <name>IK Analyzer 3</name>
  <description>A dictionary and grammar-based Chinese segmenter.</description>
  <dependencies>
    <dependency>
      <groupId>org.apache.lucene</groupId>
      <artifactId>lucene-core</artifactId>
      <version>3.0.3</version>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.apache.solr</groupId>
      <artifactId>solr-core</artifactId>
      <version>1.4.1</version>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.lucene</groupId>
      <artifactId>lucene-analyzers</artifactId>
      <version>3.0.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.lucene</groupId>
      <artifactId>lucene-smartcn</artifactId>
      <version>3.0.3</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

第三步 :打开CMD,进入到mylib文件夹,运行下面命令

E:\test>mvn install:install-file -Dfile=文件名.jar -DgroupId=组织名 -DartifactId=项目名
-Dversion=版本号 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom
---
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/3.0.5/plexus-utils-3.0.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.5/plexus-utils-3.0.5.pom (3 KB at 0.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-
api/2.0.6/maven-plugin-api-2.0.6.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project
/2.0.6/maven-project-2.0.6.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-setting
s/2.0.6/maven-settings-2.0.6.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile
/2.0.6/maven-profile-2.0.6.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-
registry/2.0.6/maven-plugin-registry-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-r
egistry/2.0.6/maven-plugin-registry-2.0.6.jar (29 KB at 15.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-al
pha-2/classworlds-1.1-alpha-2.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/
2.0.6/maven-profile-2.0.6.jar (35 KB at 10.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2
.0.6/maven-model-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-settings
/2.0.6/maven-settings-2.0.6.jar (48 KB at 11.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifac
t-manager/2.0.6/maven-artifact-manager-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-a
pi/2.0.6/maven-plugin-api-2.0.6.jar (13 KB at 2.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-reposit
ory-metadata/2.0.6/maven-repository-metadata-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-reposito
ry-metadata/2.0.6/maven-repository-metadata-2.0.6.jar (24 KB at 3.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifac
t/2.0.6/maven-artifact-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-alp
ha-2/classworlds-1.1-alpha-2.jar (37 KB at 5.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/3.0.5/plexus-utils-3.0.5.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
-manager/2.0.6/maven-artifact-manager-2.0.6.jar (56 KB at 6.4 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2.
0.6/maven-model-2.0.6.jar (85 KB at 6.9 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
/2.0.6/maven-artifact-2.0.6.jar (86 KB at 5.7 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project/
2.0.6/maven-project-2.0.6.jar (114 KB at 5.8 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.5/plexus-utils-3.0.5.jar (226 KB at 10.7 KB/sec)
[INFO] Installing E:\test\文件名.jar to C:\Users\Administrator\.m2\repository\组织名\
项目名\版本号\文件名.jar
[INFO] Installing C:\Users\ADMINI~1\AppData\Local\Temp\mvninstall199361744543933
8455.pom to C:\Users\Administrator\.m2\repository\组织名\项目名
\版本号\文件名.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.436 s
[INFO] Finished at: 2016-05-21T22:16:10+08:00
[INFO] Final Memory: 9M/183M
[INFO] ------------------------------------------------------------------------

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/63525c423db6d28ceeeb8d63818a85e7.html