2024-08-14
Please, don't be so gentle with me! — 5 Centimeters Per Second · Exiled Crab
Adding Local JAR Files to Maven
To make Maven use a local JAR file instead of downloading it from a remote repository, you can install the JAR into your local Maven repository. Here are two common methods:
Method 1: Use mvn install:install-file
Command
You can manually install the JAR file into your local Maven repository by using the mvn install:install-file
command. Here are the steps:
mvn install:install-file -Dfile=/path/to/your/jar/your-jar-file.jar -DgroupId=your.group.id -DartifactId=your-artifact-id -Dversion=your-version -Dpackaging=jar
For example, if you want to install the org.jkiss.dbeaver.core
JAR file, the command might look like this:
mvn install:install-file -Dfile=/home/too-young/developer/jars/org.jkiss.dbeaver.core-22.2.2-SNAPSHOT.jar -DgroupId=org.jkiss.dbeaver -DartifactId=org.jkiss.dbeaver.core -Dversion=22.2.2-SNAPSHOT -Dpackaging=jar
After doing this, Maven will find these dependencies in your local repository and won't try to download them from a remote repository.
Method 2: Add Local JAR as a Project Dependency
If you prefer not to manually install the JAR, you can also directly specify the local path in your pom.xml
. Here's how to add the local dependency:
<dependency>
<groupId>your.group.id</groupId>
<artifactId>your-artifact-id</artifactId>
<version>your-version</version>
<scope>system</scope>
<systemPath>${project.basedir}/path/to/your/jar/your-jar-file.jar</systemPath>
</dependency>
For example:
<dependency>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>org.jkiss.dbeaver.core</artifactId>
<version>22.2.2-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/org.jkiss.dbeaver.core-22.2.2-SNAPSHOT.jar</systemPath>
</dependency>
With this setup, Maven will directly use the JAR file from the specified path.
Notes
- Using
systemPath
dependencies is generally not recommended for production environments, as it reduces the flexibility of dependency management. - Whenever possible, it is better to install the local JAR into your local Maven repository to maintain consistency with Maven's dependency management.
By following these methods, you should be able to resolve issues with Maven not finding your local JAR files during the build process.