简体   繁体   English

将jar库添加到Maven项目

[英]Adding jar library to Maven project

I have a project developed in Maven. 我有一个在Maven开发的项目。 I want to add new jar file to classpath. 我想将新的jar文件添加到classpath。 I added new dependency in pom.xml file: 我在pom.xml文件中添加了新的依赖项:

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

All the jar libraries are in lib directory. 所有jar库都在lib目录中。 The name of all the libraries matches artifactId-version.jar and their locations are (inside lib directory) groupId/artifactId/version. 所有库的名称都与artifactId-version.jar匹配,它们的位置是(在lib目录中)groupId / artifactId / version。 So I did the same for my mzmatch-1.2.13.jar file. 所以我为我的mzmatch-1.2.13.jar文件做了同样的事情。

Apart from adding new dependency in pom file, I added my jar to class-path in Manifest.MF file. 除了在pom文件中添加新依赖项之外,我将jar添加到Manifest.MF文件中的class-path。 But the software still doesnt see my jar. 但该软件仍然没有看到我的罐子。 What else should I do? 我还该怎么办? Or I didnt add my library correctly? 或者我没有正确添加我的库?

I'm assuming this is a jar that you developed, and now want Maven to pick it up as a dependency. 我假设这是一个你开发的jar,现在希望Maven把它当作一个依赖。 To do that, you need to install it to your local Maven repository. 为此,您需要将其安装到本地Maven存储库。 Not the lib directory of your project, but the .m2 directory (probably off your home directory in Windows). 不是项目的lib目录,而是.m2目录(可能是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. 编辑1:我假设OP不在更大的团队中工作。 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 . 如果开发团队中的任何其他人都需要依赖关系,则需要将其部署到共享内部工件存储库,如NexusArtifactory 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. 编辑2:在pom.xml中添加库作为依赖项可确保Maven在编译此新项目的代码时将其置于类路径中。 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 . 如果你想在运行时(例如,如果你想要一个可执行jar),并且想要在MANIFEST.MF中的Class-Path条目中使用它,那么你可以让Maven进行设置 That still doesn't put the mzmatch-1.2.13.jar file in the same directory as your new project. 这仍然没有将mzmatch-1.2.13.jar文件放在与新项目相同的目录中。 If you don't want to do that manually, again Maven can do it for you . 如果您不想手动执行此操作,Maven可以再次为您执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM