Add self-developed dependency packages to the Maven local repository

Source: Internet
Author: User
Tags solr

Add self-developed dependency packages to the Maven local repository

Maven adds self-developed dependency packages to the pom file, which are certainly not in the Maven repository (http://repo.maven.apache.org/maven2. So how can we add packages that are not in the Maven repository to the local Maven repository? Very simple. Here, the IKAnalyzer. jar package is used as an example.

Step 1: store the IKAnalyzer. jar package in a folder, such as the test folder.
Step 2: Create an IKAnalyzer. jar package-related pom. xml file, which must be in pom. define the maven coordinates and corresponding dependent code in xml, and store the pom file in the same folder as the jar file, IKAnalyzer. the jar coordinates and dependency Code are as follows:

<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/xsd/maven-4.0.0.xsd">
<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>

Step 3: Open CMD, enter the mylib folder, and run the following command

E: \ test> mvn install: install-file-Dfile = file name. jar-DgroupId = Organization Name-DartifactId = project name
-Dversion = version-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 \ file name. jar to C: \ Users \ Administrator \. m2 \ repository \ organization name \
Project name \ version \ file name. jar
[INFO] Installing C: \ Users \ ADMINI ~ 1 \ AppData \ Local \ Temp \ mvninstall199361744543933
8455. pom to C: \ Users \ Administrator \. m2 \ repository \ organization name \ Project Name
\ Version number \ file name. 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: 9 M/183 M
[INFO] ------------------------------------------------------------------------

In this way, you can install IKAnalyzer3.2.8.jar to the corresponding directory of your Maven local library folder. You can modify the setting values of the preceding parameters based on the actual situation of the installation package. Then you can introduce the above package in the pom. xml file through the following dependencies in the project, as follows:
 
<Dependency>
<GroupId> org. wltea </groupId>
<ArtifactId> IKAnalyzer </artifactId>
<Version> 3.2.8 </version>
</Dependency>

Of course, you may not release IKAnalyzer3.2.8.jar to your local Maven library, but introduce it through the following configuration. The effect is similar to the above:

<Dependency>
<GroupId> org. wltea </groupId>
<ArtifactId> IKAnalyzer </artifactId>
<Version> 3.2.8 </version>
<Scope> system </scope>
<SystemPath> E: \ test \ IKAnalyzer3.2.8.jar </systemPath>
</Dependency>

Maven build process details

Build a Maven repository on GitHub

Use Maven to build a Wicket project under NetBeans

Maven practice: Maven practice tutorial PDF

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.