Table of Contents
1. Local Jar package import
1.1 Import through system path
1.2 Import through the install command
2. Remote warehouse Jar package import
2.1 Central warehouse dependency
Then introduce the corresponding dependencies:
Then execute the upload command:
Home Java javaTutorial Maven Advanced Tutorial: In-depth exploration of various methods of Jar package import

Maven Advanced Tutorial: In-depth exploration of various methods of Jar package import

Feb 23, 2024 pm 02:57 PM
maven jar package import

Maven Advanced Tutorial: In-depth exploration of various methods of Jar package import

Title: Maven Advanced Tutorial: In-depth exploration of various methods of Jar package import

As a Java project management tool, Maven is widely used in project construction and dependency management etc. In the actual development process, we often use Jar packages of various third-party libraries, and how to effectively import Jar packages has become a skill that must be mastered. This article will delve into the methods of importing Jar packages in Maven, including using local Jar packages, remote warehouse Jar packages, and custom Jar packages. It will also give specific code examples to help readers better understand and apply these techniques. .

1. Local Jar package import

1.1 Import through system path

In the pom.xml file of the Maven project, you can import by specifying the system path of the local Jar package , the sample code is as follows:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/example.jar</systemPath>
</dependency>
Copy after login

1.2 Import through the install command

First install the local Jar package to the local Maven repository, execute the following command in the command line:

mvn install:install-file -Dfile=path/to/example.jar -DgroupId=com.example -DartifactId=example -Dversion=1.0 -Dpackaging=jar
Copy after login

Then Introduce this dependency in the pom.xml file:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0</version>
</dependency>
Copy after login
Copy after login

2. Remote warehouse Jar package import

2.1 Central warehouse dependency

Maven will download the Jar package from the central warehouse by default , you only need to add the corresponding coordinates in the pom. Package, you can add warehouse configuration in pom.xml, the sample code is as follows:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>
Copy after login

Then introduce the corresponding dependencies:

<repositories>
    <repository>
        <id>custom-repo</id>
        <url>http://example.com/maven-repo/</url>
    </repository>
</repositories>
Copy after login

3. Custom Jar package import

For Some customized Jar packages can be packaged and uploaded to the Maven repository through the Maven plug-in, and then the dependencies can be introduced for use. The sample code is as follows:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0</version>
</dependency>
Copy after login
Copy after login

Then execute the upload command:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.7</version>
    <configuration>
        <url>http://example.com/maven-repo</url>
    </configuration>
</plugin>
Copy after login

Finally introduce dependencies in pom.xml:

mvn deploy:deploy-file -Dfile=path/to/example.jar -DgroupId=com.example -DartifactId=example -Dversion=1.0 -Dpackaging=jar -Durl=http://example.com/maven-repo
Copy after login

Through the introduction of this article, readers can have a more comprehensive understanding There are various ways to import Jar packages in Maven, including local Jar packages, remote warehouse Jar packages, and custom Jar packages. I hope these specific code examples can help readers use Maven to manage dependencies more flexibly in actual projects and improve development efficiency.

The above is the detailed content of Maven Advanced Tutorial: In-depth exploration of various methods of Jar package import. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to import local songs from NetEase Cloud Music How to import local songs How to import local songs from NetEase Cloud Music How to import local songs Mar 13, 2024 am 11:19 AM

When we use this platform to listen to songs, most of them should have some songs that you want to listen to. Of course, some things may not be listened to because there is no copyright. Of course, we can also directly use some songs imported locally. Go up there so you can listen. We can download some songs and directly convert them into mp3 formats, so that they can be scanned on the mobile phone for import and other situations. However, for most users, they don’t know much about importing local song content, so in order to solve these problems well, today the editor will also explain it to you. The content method allows you to make better choices without asking. If you are interested,

How to import oiv files into openiv How to import oiv files into openiv Feb 21, 2024 pm 11:12 PM

OpenIV is a very convenient tool that can be used to import OIV files in GTA games. OIV files are a specific file format used to package mod or modification files into an easy-to-install format. This article will introduce how to use OpenIV to import OIV files. First, make sure you have the OpenIV software installed. If not, you can download it from the official website and follow the instructions to install it. Next, download the required OIV file from a trusted source. You can find various GTA modding communities or M

How to solve the problem of garbled characters when importing Chinese data into Oracle? How to solve the problem of garbled characters when importing Chinese data into Oracle? Mar 10, 2024 am 09:54 AM

Title: Methods and code examples to solve the problem of garbled characters when importing Chinese data into Oracle. When importing Chinese data into Oracle database, garbled characters often appear. This may be due to incorrect database character set settings or encoding conversion problems during the import process. . In order to solve this problem, we can take some methods to ensure that the imported Chinese data can be displayed correctly. The following are some solutions and specific code examples: 1. Check the database character set settings In the Oracle database, the character set settings are

Java Maven build tool advancement: optimizing compilation speed and dependency management Java Maven build tool advancement: optimizing compilation speed and dependency management Apr 17, 2024 pm 06:42 PM

Optimize Maven build tools: Optimize compilation speed: Take advantage of parallel compilation and incremental compilation. Optimize dependencies: Analyze dependency trees and use BOM (bill of materials) to manage transitive dependencies. Practical case: illustrate optimizing compilation speed and dependency management through examples.

How to import soda music to an external playlist How to import soda music to an external playlist How to import soda music to an external playlist How to import soda music to an external playlist Mar 22, 2024 pm 03:51 PM

Do you know how to import external playlists on Soda Music App? Many users of the latest version of Soda Music App, when importing some playlists, do not like to import their own songs into the playlist, but this is limited. You can manage the classification of some of your songs very well when you listen to it, so friends who have ideas must give it a try and find out more. I believe you will like it, and you can have any ideas. Step-by-step tutorial for importing external playlists from Soda Music: 1. On the Soda Music app page, click and select the lower right corner to create a playlist. 2. Create a page, enter the playlist name, and click Save. 3. On the My Playlist page, select Add Songs. 4. Search, select your favorite songs, and add them to the playlist

Best practices and recommended methods for setting Java versions in Maven Best practices and recommended methods for setting Java versions in Maven Feb 22, 2024 pm 03:18 PM

When using Maven to build a Java project, you often encounter situations where you need to set the Java version. Correctly setting the Java version can not only ensure that the project runs normally in different environments, but also avoid some compatibility issues and improve the stability and maintainability of the project. This article will introduce the best practices and recommended methods for setting Java versions in Maven, and provide specific code examples for reference. 1. Set the Java version in the pom.xml file. In the pom.xml file of the Maven project, you can

Complete guide to install Maven on CentOS7 Complete guide to install Maven on CentOS7 Feb 20, 2024 am 10:57 AM

Detailed tutorial on how to install Maven under CentOS7 Maven is a popular project management tool developed by the Apache Software Foundation. It is mainly used to manage the construction, dependency management and project information management of Java projects. This article will detail the steps on how to install Maven in CentOS7 system, as well as specific code examples. Step 1: Update the system Before installing Maven, you first need to ensure that the system is up to date. Open a terminal and run the following command to update the system: sudoy

How to disable test cases in Maven? How to disable test cases in Maven? Feb 26, 2024 am 09:57 AM

Maven is an open source project management tool that is commonly used for tasks such as construction, dependency management, and document release of Java projects. When using Maven for project build, sometimes we want to ignore the testing phase when executing commands such as mvnpackage, which will improve the build speed in some cases, especially when a prototype or test environment needs to be built quickly. This article will detail how to ignore the testing phase in Maven, with specific code examples. Why you should ignore testing During project development, it is often

See all articles