Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding jar library to Maven project

Tags:

java

maven

jar

I have a project developed in Maven. I want to add new jar file to classpath. I added new dependency in pom.xml file:

<dependency>
<groupId>mzmatch</groupId>
<artifactId>mzmatch</artifactId>
<version>1.2.13</version>
</dependency>

All the jar libraries are in lib directory. The name of all the libraries matches artifactId-version.jar and their locations are (inside lib directory) groupId/artifactId/version. So I did the same for my mzmatch-1.2.13.jar file.

Apart from adding new dependency in pom file, I added my jar to class-path in Manifest.MF file. But the software still doesnt see my jar. What else should I do? Or I didnt add my library correctly?

like image 911
user1574866 Avatar asked Jan 16 '23 19:01

user1574866


1 Answers

I'm assuming this is a jar that you developed, and now want Maven to pick it up as a dependency. To do that, you need to install it to your local Maven repository. Not the lib directory of your project, but the .m2 directory (probably off your home directory in Windows). You probably want to run this from the command line:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=mzmatch -DartifactId=mzmatch -Dversion=1.2.13 -Dpackaging=jar

Take a look here for more info.

EDIT 1: I'm assuming that the OP is not working within a larger team. If the dependency were required by anyone else within a development team, then it would need to be deployed to a shared internal artifact repository, like Nexus or Artifactory. These applications have a page for uploading your artifacts.

EDIT 2: Adding a library as a dependency in your pom.xml ensures that Maven will have it on the classpath when it compiles the code for this new project. If you want it there at runtime (say, if you want an executable jar), and you want to have it in the Class-Path entry in your MANIFEST.MF, then you could have Maven set it up. That still doesn't put the mzmatch-1.2.13.jar file in the same directory as your new project. If you don't want to do that manually, again Maven can do it for you.

like image 72
davidfmatheson Avatar answered Jan 21 '23 08:01

davidfmatheson