How to add local jar files to a Maven project?
Install the JAR into your local Maven repository (typically .m2
in your home folder) as follows:
mvn install:install-file \
-Dfile=<path-to-file> \
-DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=<packaging> \
-DgeneratePom=true
Where each refers to:
<path-to-file>
: the path to the file to load e.g → c:\kaptcha-2.3.jar
<group-id>
: the group that the file should be registered under e.g → com.google.code
<artifact-id>
: the artifact name for the file e.g → kaptcha
<version>
: the version of the file e.g → 2.3
<packaging>
: the packaging of the file e.g. → jar
Reference
- Maven FAQ: I have a jar that I want to put into my local repository. How can I copy it in?
- Maven Install Plugin Usage: The
install:install-file
goal
Maven: add a folder or jar file into current classpath
This might have been asked before. See Can I add jars to maven 2 build classpath without installing them?
In a nutshell: include your jar as dependency with system scope. This requires specifying the absolute path to the jar.
See also http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Maven : How to package external jars(folder) in Maven project
My solution : Maven pluggin addjar let us add all jar at a place(projectdirectory/lib in this case).
this enables you to add these jar's in the final package(jar in my case) when you maven build, but to run locally you have to add those jar files directly in the classpath.
<plugin>
<groupId>com.googlecode.addjars-maven-plugin</groupId>
<artifactId>addjars-maven-plugin</artifactId>
<version>1.0.5</version>
<executions>
<execution>
<goals>
<goal>add-jars</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/lib</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Now create a shade jar using mvn clean install shade:shade
Can I add LOCAL source jars to maven 2 build without installing them so they can be referenced in eclipse?
If you're using the m2e Eclipse plugin, there's an option to download sources for all dependencies:
- Right-click the project
- Maven > Download Sources
If you're not using m2e, you can download the sources from command line using
mvn dependency:sources
To get them into Eclipse, you can use
mvn eclipse:eclipse -DdownloadSources=true
The easiest way to handle this is through m2e though. I strongly recommend to install it, as it will simplify all other Maven handling from within Eclipse.
If the sources are not available in a public repository, you can either
- Upload the sources to your local Maven repository, if you're using something like Nexus, Archiva or Artifactory.
- Install them locally using the Maven Install plugin: http://maven.apache.org/plugins/maven-install-plugin/examples/installing-secondary-artifacts.html The disadvantage is that it will only be visible to yourself in this case.
Out of the two, the first one (local Maven repository/proxy) is recommended.
Related Topics
How to Assert That a Certain Exception Is Thrown in Junit Tests
Arrays.Aslist() Not Working as It Should
What Does Servletcontext.Getrealpath("/") Mean and When Should I Use It
Quality of Image After Resize Very Low - Java
How to Pretty Print Xml from Java
To Prevent a Memory Leak, the Jdbc Driver Has Been Forcibly Unregistered
Getting the Name of the Currently Executing Method
How to Determine Day of Week by Passing Specific Date
What Are Java Command Line Options to Set to Allow Jvm to Be Remotely Debugged
How to Prevent Java.Lang.Numberformatexception: For Input String: "N/A"
Including Dependencies in a Jar With Maven
What's the Difference Between Instant and Localdatetime
How to Run a Batch File from My Java Application
Adding External Library to Artifact Jar in Intellij Idea
Java Serializable Object to Byte Array
How to Make a JPA Onetoone Relation Lazy