Home >Java >javaTutorial >How Can I Inject a Dependency from a Relative JAR Path in Maven?
Maven: Dependency Injection Using a Relative JAR Path
Adding a proprietary JAR to a Maven project as a dependency without storing it in a repository can be complex. However, this approach allows for seamless compilation and execution of Maven commands without requiring developers to manually add it to a repository.
Solution:
To achieve this, create a local repository within the project and install the JAR using the install:install-file plugin. Configure the plugin to specify the local repository path. Do not use the system scope for the dependency.
Steps:
<repositories> <repository> <id>my-local-repo</id> <url>file://${project.basedir}/my-repo</url> </repository> </repositories>
mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file \ -Dfile=<path-to-file> -DgroupId=<myGroup> \ -DartifactId=<myArtifactId> -Dversion=<myVersion> \ -Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>
<dependency> <groupId>your.group.id</groupId> <artifactId>3rdparty</artifactId> <version>X.Y.Z</version> </dependency>
Benefits:
Note:
The above is the detailed content of How Can I Inject a Dependency from a Relative JAR Path in Maven?. For more information, please follow other related articles on the PHP Chinese website!