Maven add jar without install

I have some problem with adding external jar in to maven project without install it. If I install JAR file other people who working on same project, have to install same JAR. them I want to avoid that issue.

First need to place jar file inside lib folder. After that using following POM entry we can use it as dependency.

<dependency>
   <groupId>com.chandana</groupId>
   <artifactId>example</artifactId>
   <version>0.1</version>
   <scope>system</scope>
   <systemPath>${basedir}/lib/example.0.1.jar</systemPath>
</dependency>


Ex:
<dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.5.0</version>
   <scope>system</scope>
   <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>

 Here very important option is <scope>system</scope>. It's say dependency provide with system, no need to look at repository. More about System Dependency




Comments

Rather than using system dependencies, consider installing a corporate artifact repository like Artifactory or Nexus. To share artifacts with a team, everybody using a corporate repository like this helps a lot. As well, it becomes a destination for your team's artifacts (shared libraries, etc.). Finally, it can help manage proxy rules for the team by centrally managing the at the corporate repo. (There are more maven repositories than Central to proxy.)
Mathew Bukowicz said…
@Anthony: That was exactly what I was going to write. When using Maven, you should avoid adding custom jars through classpath. Maybe in your case it is better to use Ant or "constrain" yourself to a specific IDE?
Jeff said…
Very bad practice. I would not recommend this. System scope should be used with extreme care. Don't try to fight Maven
@All, Thanks for giving me great advice and comments. As three of you mentioned, we can install install maven dependency like this http://java-wisdom.blogspot.com/2011/12/manually-install-maven-dependency.html
Mathew Bukowicz said…
@Chandana, this is also not recommended, because everyone on your team would have to install it manually in their local repository. The best you can do is, as Anthony said, install Artifactory or Nexus server and publish your jars there. Then, your teammates would have to point in their Maven configurations to that repository. When building application Maven will automatically resolve this dependency and download it from your Artifactory/Nexus server.

Popular posts from this blog

Secure Spring Boot REST API using Basic Authentication

Integrating Swagger with Spring Boot REST API

Building a RESTFul Service using Spring Boot