简体   繁体   English

Maven Build Jar

[英]Maven Build Jar

I am working on Maven project and I have a jar app-client.jar which have dependency on app-core.jar. 我正在Maven项目上工作,我有一个jar app-client.jar,它依赖于app-core.jar。 So I have a pom.xml for app-client.jar and that pom.xml has dependency of app-core so we added dependency of app-core in this pom.xml. 所以我有一个app-client.jar的pom.xml,而pom.xml具有app-core的依赖关系,因此我们在此pom.xml中添加了app-core的依赖关系。 Now I wanna use the app-client.jar in my main project. 现在,我要在主项目中使用app-client.jar。 Because this jar is build locally and not available at remote repository. 因为此jar是在本地构建的,因此在远程存储库中不可用。 So I did add the app-client and also specify the location repository where it will located. 因此,我确实添加了应用程序客户端,并且还指定了它将定位的位置存储库。 as following.. 如下

 <repositories> <repository> <id>repo</id> <releases> <enabled>true</enabled> <checksumPolicy>ignore</checksumPolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <url>file://${project.basedir}/../lib</url> </repository> <repositories> <dependencies> <dependency> <groupId>com.sample</groupId> <artifactId>app-client</artifactId> <version>1.0</version> </dependency> </dependencies> 

and also I put my jar as following [My Module] / [com] / [sample] /[app-client] /[1.0]/app-client-1.0.jar 而且我把我的罐子如下[我的模块] / [com] / [示例] / [应用程序客户端] /[1.0]/app-client-1.0.jar

When I run mvn clean install I got error app-client's pom.xml not found. 当我运行mvn clean install时,出现错误,未找到app-client的pom.xml。 and build get failed. 并建立失败。 Usually when I use single jar then its working fine, but if I use jar having dependency with other jar it getting failed. 通常,当我使用单个jar时,它可以正常工作,但是如果我使用与其他jar具有依赖关系的jar,它将失败。

So how can I build my app-client jar and their pom so that it behave normal and also deploy app-core.jar too. 因此,我该如何构建我的应用程序客户端jar和它们的pom,使其行为正常,同时也部署app-core.jar。

firstly when you are building app-client.jar build a fat jar which includes app-core.jar dependency. 首先,在构建app-client.jar时,构建一个包含app-core.jar依赖项的胖jar。

Next copying app-client-1.0.jar into the specified location of local repo doesn't work, to add this jar into your local repo use this command mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> . 接下来将app-client-1.0.jar复制到本地存储库的指定位置不起作用,要将此jar添加到本地存储库中,请使用以下命令mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

If you build app-client.jar with mvn clean install , then it will be installed into your Maven local repository ( .../.m2/repository ). 如果您使用mvn clean install构建app-client.jar ,那么它将被安装到您的Maven本地存储库( .../.m2/repository )中。 Then any other project on the same computer can reference it in its pom without further information. 然后,同一台计算机上的任何其他项目都可以在其pom中引用它,而无需进一步的信息。 So no <repositories> entry necessary. 因此,无需任何<repositories>条目。

If you want to work with multiple people on the same project, use a Nexus/Artifactory server to share the jars. 如果要在同一项目上与多个人一起工作,请使用Nexus / Artifactory服务器共享jar。

Solutions with lib folders and system paths are deprecated and cause trouble. 不建议使用lib文件夹和系统路径的解决方案,并且会引起麻烦。

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

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