Add a custom jar package to Maven

Source: Internet
Author: User

Introduction: In Software projects, MAVEN provides an integrated class library management system, which is very useful. However, if the new class library jar is not available on the network, how do I add it locally in accordance with MAVEN's rules? This article will show you the new process with a small example.

Background introduction:

A maven-managed Java project that provides a system-level pom.xml that defines the class libraries used throughout the project.

Demand:

You need to add a custom class library to the current project. Assume that the current class library file name is: Abc.jar.,

How do I add a class library?

1. Find the current MAVEN Repository class library location

Typically, by default, the current user directory is under the window System: C:\Users\ZhangSan. Where Zhangsan is the current user name in the system. Under the Linux system is/home/${user_name}.

In this directory, there is a hidden directory. M2/repository is designed to store the various class library files that are managed in the MAVEN system.

2. Assume that the current Abc.jar version is 1.0

3. The new dependency fragment in the new Pom.xml is:

[HTML]View PlainCopy
  1. <dependency>
  2. <groupId>mylocaljar</groupId>
  3. <artifactid>abc</artifactid>
  4. <version>1.0</version>
  5. </Dependency>

4. The new directory to be created under. M2/repository is:

Mylocaljar/abc/1.0/abc-1.0.jar

If GroupID is MyLocalJar.myjar.util, it is decomposed into a 3-tier directory structure: mylocaljar/myjar/util/1.0.

Note: The Abc.jar has been added to the version number, with the same name as Abc-1.0.jar.

Then refresh the system to be able to use it normally.

Summarize:

Maven actually follows a simple principle, which is to isolate the path based on the hierarchy of folders, and Groupid,arrtifactid,version is converted to the directory structure in the file system. For the jar packages in the MAVEN system, you also need to add version information, such as abc-1.0 here.

Based on multiple versions, different directories are generated depending on the version, and this is what MAVEN does under managing multiple versions of the class package.

Source: http://blog.csdn.net/blueheart20/article/details/26565149/

Add a custom jar package to Maven

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.