The process of installing a Maven artifact with source code via the command line involves several steps. First, ensure that Maven is installed and can be run from the command line. Next, you need to obtain or specify the source JAR, compiled JAR file, and POM file for the artifact. Below are the specific steps and commands:
Step 1: Prepare Files
Ensure you have the following files:
your-artifact-x.x.x.jar: compiled JAR fileyour-artifact-x.x.x-sources.jar: source JARpom.xml: the project's POM file, describing the project's configuration and dependencies
Step 2: Use Maven Command to Install
Open the command line tool, navigate to the directory containing these files, and execute the following command:
bashmvn install:install-file -Dfile=your-artifact-x.x.x.jar -Dsources=your-artifact-x.x.x-sources.jar -DpomFile=pom.xml
The parameters in this command mean:
-Dfile: specifies the path to your JAR file-Dsources: specifies the path to your source JAR-DpomFile: specifies the path to your POM file
Example
Suppose we have an artifact named example-artifact-1.0.0.jar, with the corresponding source JAR named example-artifact-1.0.0-sources.jar, and all these files are in the current directory along with a pom.xml file. We would install it as follows:
bashmvn install:install-file -Dfile=example-artifact-1.0.0.jar -Dsources=example-artifact-1.0.0-sources.jar -DpomFile=pom.xml
Verify Installation
After installation, the artifact will be added to your local Maven repository. You can verify the installation by adding a dependency to your project's POM file:
xml<dependency> <groupId>your-group-id</groupId> <artifactId>your-artifact-id</artifactId> <version>x.x.x</version> </dependency>
Ensure that the groupId, artifactId, and version match the settings in your pom.xml.
Through this process, the Maven artifact and its source code are successfully installed in the local repository and can be depended upon in other projects.