如何将本地jar文件添加到Maven项目?

如何直接在项目的库源代码中添加本地jar文件(还不是Maven存储库的一部分)?

1456201 次浏览

将JAR安装到本地Maven存储库中(通常在主文件夹中为.m2),如下所示:

mvn install:install-file \-Dfile=<path-to-file> \-DgroupId=<group-id> \-DartifactId=<artifact-id> \-Dversion=<version> \-Dpackaging=<packaging> \-DgeneratePom=true

其中每一项均指:

<path-to-file>:要加载的文件的路径,例如→c:\kaptcha-2.3.jar

<group-id>:文件应该注册在例如→com.google.code下的组

<artifact-id>:文件的工件名称,例如→kaptcha

<version>:文件的版本,例如→2.3

<packaging>:文件的包装,例如→jar

参考

首选方法是创建自己的远程存储库。

有关如何执行此操作的详细信息,请参阅这里。看看“上传到远程存储库”部分。

当然,您可以将罐子添加到该文件夹中。但也许它并不是您想要实现的…

如果您需要这些jar进行编译,请检查以下相关问题:我可以在不安装jars的情况下将jars添加到maven 2 build classpath吗?

另外,在任何人建议之前,不要使用系统范围。

一种方法是将其上传到您自己的Maven存储库管理器(例如Nexus)。无论如何,拥有自己的存储库管理器是一种很好的做法。

我最近看到的另一个好方法是在您的构建生命周期中包含Maven Install Plugin:您在POM中声明将文件安装到本地存储库。这虽然开销很小,但不涉及手动步骤。

http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html

你可以直接添加本地依赖项(如构建包含专有库的maven项目所述),如下所示:

<dependency><groupId>com.sample</groupId><artifactId>sample</artifactId><version>1.0</version><scope>system</scope><systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath></dependency>

更新

在新版本中,此功能被标记为已弃用,但仍在工作且尚未删除(您只需在maven启动期间在日志中看到警告)。maven组提出了有关此https://issues.apache.org/jira/browse/MNG-6523的问题(您可以参与并描述为什么此功能在某些情况下很有帮助)。我希望此功能仍然存在!

如果你问我,只要不删除该功能,我就会在我的项目中使用这个不适合存储库的只依赖一个naughty jar文件。如果此功能被删除,那么,这里有很多好的答案,我可以稍后选择!

首先,我想把这个答案归功于一个匿名的Stack Overflow用户——我很确定我以前在这里见过类似的答案——但现在我找不到了。

将本地JAR文件作为依赖项的最佳选择是创建一个本地Maven存储库。这样的存储库只不过是一个包含pom文件的适当目录结构。

我的例子:我的主项目在${master_project}位置,子项目1在${master_project}/${subproject1}上。

然后我在以下位置创建一个Maven存储库:${master_project}/local-maven-repo.

在位于${master_project}/${subproject1}/pom.xml的subproject ect1中的pom文件中,需要指定将文件路径作为URL参数的存储库:

<repositories><repository><id>local-maven-repo</id><url>file:///${project.parent.basedir}/local-maven-repo</url></repository></repositories>

可以像指定任何其他存储库一样指定依赖项。这使您的pom存储库独立。例如,一旦所需的JAR在Maven Central中可用,您只需从本地存储库中删除它,它将从默认存储库中提取。

    <dependency><groupId>org.apache.felix</groupId><artifactId>org.apache.felix.servicebinder</artifactId><version>0.9.0-SNAPSHOT</version></dependency>

最后但并非最不重要的是使用-DlocalRepositoryPath开关将JAR文件添加到本地存储库,如下所示:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file  \-Dfile=/some/path/on/my/local/filesystem/felix/servicebinder/target/org.apache.felix.servicebinder-0.9.0-SNAPSHOT.jar \-DgroupId=org.apache.felix -DartifactId=org.apache.felix.servicebinder \-Dversion=0.9.0-SNAPSHOT -Dpackaging=jar \-DlocalRepositoryPath=${master_project}/local-maven-repo

安装JAR文件后,您的Maven存储库可以提交到代码存储库,整个设置与系统无关。(GitHub中的工作示例)。

我同意让JAR致力于源代码存储库不是一个好的做法,但在现实生活中,快速而肮脏的解决方案有时比完整的Nexus存储库更好,以托管一个您无法发布的JAR。

也看看……

<scope>compile</scope>

Maven依赖关系。这是默认值,但我发现在某些情况下显式设置该范围也Maven以在本地存储库中查找本地库。

请注意,使用本地存储库不一定是个好主意。如果这个项目与其他人共享,那么当它不起作用时,其他人都会有问题和疑问,即使在您的源代码控制系统中,jar也不可用!

尽管共享存储库是最好的答案,但如果由于某种原因无法做到这一点,那么嵌入jar比本地存储库更好。仅限本地的存储库内容会导致很多问题,尤其是随着时间的推移。

<dependency><groupId>group id name</groupId><artifactId>artifact name</artifactId><version>version number</version><scope>system</scope><systemPath>jar location</systemPath></dependency>

我想分享一段代码,你可以在其中上传一个装满jar的文件夹。当提供商没有公共存储库并且你需要手动添加大量库时,这很有用。我决定构建一个. bat而不是直接调用maven,因为它可能是内存不足错误。它是为Windows环境准备的,但很容易使其适应Linux操作系统:

import java.io.File;import java.io.IOException;import java.io.PrintWriter;import java.util.Date;import java.util.jar.Attributes;import java.util.jar.JarFile;import java.util.jar.Manifest;
public class CreateMavenRepoApp {
private static final String OCB_PLUGIN_FOLDER = "C://your_folder_with_jars";
public static void main(String[] args) throws IOException {
File directory = new File();//get all the files from a directoryPrintWriter writer = new PrintWriter("update_repo_maven.bat", "UTF-8");writer.println("rem "+ new Date());File[] fList = directory.listFiles();for (File file : fList){if (file.isFile()){String absolutePath = file.getAbsolutePath() ;Manifest  m = new JarFile(absolutePath).getManifest();Attributes attributes = m.getMainAttributes();String symbolicName = attributes.getValue("Bundle-SymbolicName");
if(symbolicName!=null &&symbolicName.contains("com.yourCompany.yourProject")) {String[] parts =symbolicName.split("\\.");String artifactId = parts[parts.length-1];String groupId = symbolicName.substring(0,symbolicName.length()-artifactId.length()-1);String version = attributes.getValue("Bundle-Version");String mavenLine= "call mvn org.apache.maven.plugins:maven-install-plugin:2.5.1:install-file -Dfile="+ absolutePath+" -DgroupId="+ groupId+" -DartifactId="+ artifactId+" -Dversion="+ version+" -Dpackaging=jar ";writer.println(mavenLine);}
}}writer.close();}
}

从任何IDE运行此main后,运行update_repo_maven.bat.

创建一个新文件夹,假设local-maven-repo位于Maven项目的根目录。

只需在pom.xml<project>中添加一个本地repo:

<repositories><repository><id>local-maven-repo</id><url>file:///${project.basedir}/local-maven-repo</url></repository></repositories>

然后,对于要安装的每个外部jar,转到项目的根目录并执行:

mvn deploy:deploy-file -DgroupId=[GROUP] -DartifactId=[ARTIFACT] -Dversion=[VERS] -Durl=file:./local-maven-repo/ -DrepositoryId=local-maven-repo -DupdateReleaseInfo=true -Dfile=[FILE_PATH]

我喜欢这样的解决方案-在pom文件中使用maven-install-plugin

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-install-plugin</artifactId><version>2.5.2</version><executions><execution><phase>initialize</phase><goals><goal>install-file</goal></goals><configuration><file>lib/yourJar.jar</file><groupId>com.somegroup.id</groupId><artifactId>artefact-id</artifactId><version>x.y.z</version><packaging>jar</packaging></configuration></execution></executions></plugin>

在这种情况下,您可以执行mvn initialize并将jar安装在本地maven存储库中。现在,此jar在这台机器上的任何maven步骤中都可用(不要忘记将此依赖项作为任何其他maven依赖项包含在带有<dependency></dependency>标签的pom中)。也可以将jar install不绑定到initialize步骤,而是绑定到您喜欢的任何其他步骤。

这是较新版本的简短语法:

mvn install:install-file -Dfile=<path-to-file>

它在Apache Maven构建JAR时工作-最常见的情况。然后它将在META-INF目录的子文件夹中包含一个pom.xml,默认情况下将读取该文件夹。

来源:http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

在您的本地存储库中,您可以通过发出命令来安装jar

 mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

按照这个有用的链接在mkYoung的网站上做同样的事情。你也可以检查Maven指南同样

要安装第三方jar,请调用如下命令

mvn install:install-file -DgroupId= -DartifactId= -Dversion= -Dpackaging=jar -Dfile=path

另一个有趣的情况是,当你想在你的项目中拥有私有的maven jar时。你可能想保留Maven的功能来解决传递依赖关系。解决方案相当简单。

  1. 在项目中创建文件夹libs
  2. 在pom.xml文件中添加以下行

    <properties><local.repository.folder>${pom.basedir}/libs/</local.repository.folder></properties>
    <repositories><repository><id>local-maven-repository</id><url>file://${local.repository.folder}</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories>
  3. Open the .m2/repository folder and copy the directory structure of the project you want to import into the libs folder.

E.g. suppose you want to import the dependency

<dependency><groupId>com.mycompany.myproject</groupId><artifactId>myproject</artifactId><version>1.2.3</version></dependency>

只需继续. m2/仓库,您将看到以下文件夹

com/我的公司/我的项目/1.2.3

复制libs文件夹中的所有内容(再次,包括. m2/仓库下的文件夹),您就完成了。

在POM文件中添加您自己的本地JAR并在maven构建中使用它。

mvn install:install-file -Dfile=path-to-jar -DgroupId=owngroupid -DartifactId=ownartifactid -Dversion=ownversion -Dpackaging=jar

例如:

mvn install:install-file -Dfile=path-to-jar -DgroupId=com.decompiler -DartifactId=jd-core-java -Dversion=1.2 -Dpackaging=jar

然后将其添加到POM中,如下所示:

在此处输入图片描述

出于某种原因,在我正在维护的Web应用程序中,Alireza Fattahi的解决方案JJ Roman的解决方案都没有正常工作。在这两种情况下,编译都正常(它看到了jar),但包装未能将jar包含在war中。

我设法使其工作的唯一方法是将罐子放在/src/main/webapp/WEB-INF/lib/上,然后将其与Fattahis或Roman的解决方案相结合。

命令行:

mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code-DartifactId=kaptcha -Dversion={version} -Dpackaging=jar

我在我的pom.xml中对一组依赖项也犯了同样的错误,结果pom.xml中没有指定依赖项的版本,并且在父存储库中提到了。出于某种原因,版本详细信息没有与此存储库同步。因此,我使用标签手动输入版本,它工作得很好。需要一点时间在父存储库中查找版本并在此处指定。但这可以仅针对显示artifactid错误的jar完成,并且有效。希望这对某人有帮助。

我认为这个问题的更好解决方案是使用安装插件说明在安装时自动安装文件。这就是我为我的项目设置的方式。

首先,添加路径(您存储本地. jar的位置)作为属性。

<properties><local.sdk>/path/to/jar</local.sdk></properties>

然后,在plugins下添加一个插件以在编译时安装jar。

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-install-plugin</artifactId><version>2.5.2</version><executions><execution><id>1</id><phase>initialize</phase><goals><goal>install-file</goal></goals><configuration><groupId>com.local.jar</groupId><artifactId>appengine-api</artifactId><version>1.0</version><packaging>jar</packaging><file>${local.sdk}/lib/impl/appengine-api.jar</file></configuration></execution><execution><id>appengine-api-stubs</id><phase>initialize</phase><goals><goal>install-file</goal></goals><configuration><groupId>com.local.jar</groupId><artifactId>appengine-api-stubs</artifactId><version>1.0</version><packaging>jar</packaging><file>${local.sdk}/lib/impl/appengine-api-stubs.jar</file></configuration></execution></executions></plugin>

最后,在依赖关系中,您可以添加jar

<dependency><groupId>com.local.jar</groupId><artifactId>appengine-api</artifactId><version>1.0</version></dependency>
<dependency><groupId>com.local.jar</groupId><artifactId>appengine-api-stubs</artifactId><version>1.0</version><scope>test</scope></dependency>

通过这样设置您的项目,即使您将项目带到另一台计算机上,项目也将继续构建(假设它在属性local.sdk指定的路径中拥有所有jar文件)。

对于groupId,使用唯一的名称以确保没有冲突。

现在,当您mvn installmvn test时,本地罐子将自动添加。

  1. mvn安装

您可以在命令行中编写代码,或者如果您使用的是eclipse内置maven右键单击项目->运行方式->运行配置…->在左面板右键单击Maven Build->新配置->在目标和基目录中编写代码:${project_loc: NameOfYourProject}->运行

mvn install:install-file-Dfile=<path-to-file>-DgroupId=<group-id>-DartifactId=<artifact-id>-Dversion=<version>-Dpackaging=<packaging>-DgeneratePom=true

其中每一项均指:

:要加载的文件的路径,例如->c:\kaptcha-2.3.jar

:文件应该注册的组,例如->com.google.code

:文件的工件名称,例如->kaptcha

:文件的版本,例如->2.3

<包装>:文件的包装,例如->jar

2.安装后,只需在pom.xml.中声明jar

 <dependency><groupId>com.google.code</groupId><artifactId>kaptcha</artifactId><version>2.3</version></dependency>

真正快速而肮脏的方法是指向本地文件,请注意“系统”现在已弃用:

<dependency><groupId>com.sample</groupId><artifactId>samplifact</artifactId><version>1.0</version><scope>system</scope><systemPath>C:\DEV\myfunnylib\yourJar.jar</systemPath></dependency>

然而,这将只存在于您的机器上(显然),对于共享来说,使用适当的m2存档(nexus/arti工厂)通常是有意义的,或者如果您没有任何这些或不想设置一个本地maven结构化存档并在pom中配置一个“存储库”:

当地:

<repositories><repository><id>my-local-repo</id><url>file://C:/DEV//mymvnrepo</url></repository></repositories>

远程:

<repositories><repository><id>my-remote-repo</id><url>http://192.168.0.1/whatever/mavenserver/youwant/repo</url></repository></repositories>

对于这个解决方案,也可以使用base dir变量创建相对路径:

<url>file:${basedir}</url>

在Apache Maven 3.5.4中,我不得不添加双引号。没有双引号,它对我不起作用。

例子:mvn install: install-file"-Dfile=jar文件的位置""-Dgroup pId=组ID""-DartifactId=工件ID""-Dversion=版本""-D包装=包类型"

依赖的重要部分是:${pom.basedir}(而不仅仅是${base dir})

<dependency><groupId>org.example</groupId><artifactId>example</artifactId><version>1.0</version><scope>system</scope><systemPath>${pom.basedir}/src/lib/example.jar</systemPath></dependency>
  1. 创建一个本地Maven存储库目录,您的项目根目录应该如下所示:
yourproject+- pom.xml+- src
  1. 为组com.example和版本1.0添加一个名为repo的标准Maven存储库目录:
yourproject+- pom.xml+- src+- repo
  1. 将工件部署到Repo中,Maven可以使用mvn部署:部署文件目标为您部署工件:
mvn deploy:deploy-file -Durl=file:///pathtoyour/repo -Dfile=your.jar -DgroupId=your.group.id -DartifactId=yourid -Dpackaging=jar -Dversion=1.0
  1. 安装对应于您的jar的pom文件,以便您的项目可以在maven构建期间从本地存储库找到jar:
mvn install:install-file -Dfile=/path-to-your-jar-1.0.jar -DpomFile=/path-to-your-pom-1.0.pom
  1. 在你的pom文件中添加repo:
<repositories><!--other repositories if any--><repository><id>project.local</id><name>project</name><url>file:${project.basedir}/repo</url></repository></repositories>
  1. 在pom中添加依赖项:
<dependency><groupId>com.groupid</groupId><artifactId>myid</artifactId><version>1.0</version></dependency>

步骤1:pom.xml中配置maven-install-plugin与目标install-file

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-install-plugin</artifactId><executions><execution><id>install-external-non-maven-jar-MWS-Client-into-local-maven-repo</id><phase>clean</phase><configuration><repositoryLayout>default</repositoryLayout><groupId>com.amazonservices.mws</groupId><artifactId>mws-client</artifactId><version>1.0</version><file>${project.basedir}/lib/MWSClientJavaRuntime-1.0.jar</file><packaging>jar</packaging><generatePom>true</generatePom></configuration><goals><goal>install-file</goal></goals></execution></executions></plugin>

确保根据您的实际文件路径编辑file路径(建议将这些外部非maven jar放在某个文件夹中,假设lib,并将此lib文件夹放在项目中,以便使用项目特定的相对路径并避免添加系统特定的绝对路径。

如果您有多个外部罐子,只需对同一maven-install-plugin中的其他罐子重复<execution>

步骤2:一旦您在pom.xml文件中配置了maven-install-plugin,您必须像往常一样在pom.xml中使用这些jar:

    <dependency><groupId>com.amazonservices.mws</groupId><artifactId>mws-client</artifactId><version>1.0</version></dependency>

请注意,maven-install-plugin仅将您的外部jar复制到本地.m2 maven存储库。仅此而已。它不会自动将这些jar作为maven依赖项包含到您的项目中。

这是一个小问题,但有时很容易错过。

不是原始问题的答案,但它可能对某人有用

使用Maven从文件夹中添加多个jar库没有正确的方法。如果只有很少的依赖项,配置maven-install-plugin可能更容易,如上面的答案所述。

然而,对于我的特殊情况,我有一个lib文件夹,其中包含100多个专有jar文件,我必须以某种方式添加这些文件。对我来说,将我的Maven项目转换为Gradle要容易得多。

plugins {id 'org.springframework.boot' version '2.2.2.RELEASE'id 'io.spring.dependency-management' version '1.0.8.RELEASE'id 'java'}
group = 'com.example'version = '0.0.1-SNAPSHOT'sourceCompatibility = '1.8'
repositories {mavenCentral()flatDir {dirs 'libs' // local libs folder}}
dependencies {implementation 'org.springframework.boot:spring-boot-starter-web'testImplementation('org.springframework.boot:spring-boot-starter-test') {exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'}    
implementation 'io.grpc:grpc-netty-shaded:1.29.0'implementation 'io.grpc:grpc-protobuf:1.29.0'implementation 'io.grpc:grpc-stub:1.29.0' // dependecies from maven central
implementation name: 'akka-actor_2.12-2.6.1' // dependecies from lib folderimplementation name: 'akka-protobuf-v3_2.12-2.6.1'implementation name: 'akka-stream_2.12-2.6.1'
}

将本地jar库及其sourcesjavadoc添加到Maven项目

如果您有预编译的jar文件和库,它们的sourcesjavadoc,那么您可以像这样将它们install到本地Maven存储库:

mvn install:install-file-Dfile=awesomeapp-1.0.1.jar \-DpomFile=awesomeapp-1.0.1.pom \-Dsources=awesomeapp-1.0.1-sources.jar \-Djavadoc=awesomeapp-1.0.1-javadoc.jar \-DgroupId=com.example \-DartifactId=awesomeapp \-Dversion=1.0.1 \-Dpackaging=jar

然后在您的项目中,您可以使用这些库:

<!-- com.example --><dependency><groupId>com.example</groupId><artifactId>awesomeapp</artifactId><version>1.0.1</version></dependency>

见:安装插件说明用法。


或者,您可以使用maven源代码插件说明maven-javadoc插件自己build这些库和它们的sourcesjavadoc,然后install它们。

示例项目:

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<url>https://example.com/awesomeapp</url>
<groupId>com.example</groupId><artifactId>awesomeapp</artifactId><name>awesomeapp</name><version>1.0.1</version><packaging>jar</packaging>
<properties><java.version>12</java.version></properties>
<build><finalName>awesomeapp</finalName><defaultGoal>install</defaultGoal>
<plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>${java.version}</source><target>${java.version}</target><encoding>UTF-8</encoding></configuration></plugin><plugin><inherited>true</inherited><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>3.2.1</version><executions><execution><id>attach-sources</id><goals><goal>jar</goal></goals></execution></executions></plugin><plugin><inherited>true</inherited><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>3.2.0</version><executions><execution><id>attach-javadocs</id><goals><goal>jar</goal></goals></execution></executions></plugin></plugins></build></project>

执行maveninstall目标:

mvn install

检查您当地的Maven存储库:

~/.m2/repository/com/example/awesomeapp/1.0.1/├─ _remote.repositories├─ awesomeapp-1.0.1.jar├─ awesomeapp-1.0.1.pom├─ awesomeapp-1.0.1-javadoc.jar└─ awesomeapp-1.0.1-sources.jar

你可以使用这个库:

<!-- com.example --><dependency><groupId>com.example</groupId><artifactId>awesomeapp</artifactId><version>1.0.1</version></dependency>

我的阴影jar文件不包含使用AlirezaFattahi解决方案的第三方库。然而,我记得上次我在同一个项目中尝试过它后它就起作用了。所以,我尝试了自己的解决方案:

  1. mkdir. m2/repositories目录下的项目路径(类似于该目录下的其他maven依赖目录)
  2. 将第三方jar文件放入其中。
  3. 像maven存储库上的库一样添加依赖项。

最后,它为我工作:)

也许有人会感兴趣:https://github.com/Limraj/maven-artifact-generator

控制台程序在本地存储库中生成maven工件,并根据jar的路径配置pom.xml的依赖项。您可以对一个文件执行此操作,但如果您有多个jar文件,则最有用。

路径罐:java-jarmaven-artifact-generator-X.X.X.jar-ppath_to_jars-gcom.test-V 1.2.3-P jar

jar:java-jarmaven-artifact-generator-X.X.X.jar-ffile_jar-gcom.test-V 1.2.3-P jar

这将在本地maven存储库中生成一个工件,并为pom.xml生成依赖项gen.log.ArtifactId是jar文件的名称。

需要安装maven。在widnows 7和macOS X(unix/linux)上进行测试。

在我的例子中,原来我现有的maven构建已经将有问题的jar文件安装到我的本地存储库中,但我没有看到预期的结果,因为本地构建生成的工件中带有后缀“-SNAPSHOT”。对我来说,非常简单的解决方案是更新使用本地构建jar文件的项目的pom.xml文件,以匹配名称。

<myproject.foo.version>1.88-SNAPSHOT</myproject.foo.version>

而不是

<myproject.foo.version>1.88</myproject.foo.version>

要点是,如果您的jar文件似乎已经在您的本地. m2/maven存储库中,那么它很可能是,您只需要相应地更新您的依赖项。

如果您是Spring开发人员,您会发现您从Spring Boot版本生成的JAR在另一个版本中不能作为依赖项JAR工作。检查您的POM是否有以下内容:

<plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin>

还要检查,如果您运行mvn package,是否在target/目录中看到.jar.original文件以及. jar。如果是这样,您需要将.jar.original文件用于任何本地开发(将其放入lib/或其他东西中)。

当然,您可以解决这个问题;请参阅原始帖子,它引用了Spring的插件手册。我认为,您需要<configuration> <attach>false</attach> <configuration>,然后您必须部署,Maven应该使用.jar.original文件。我自己没有尝试过,所以请告诉我!

指向${project.directory}/repo/或file://uri的pom存储库可以使用源代码驻留的jarfile,用于一个简单的项目的deps及时冻结。这些不会泄漏到系统~/. m2存储库中,但会影响maven版本选择对(通常是最近的)顶层的选择。

对于在分发时捆绑的现有deps,类似于阴影但更直接,如果您可以使用“目标”作为您最喜欢的结构或maven的默认值运行:

-cp "$PWD/target/classes:$PWD/target/lib/*" pkg.random.ClassWithMain

然后

<build><plugins><plugin><artifactId>maven-dependency-plugin</artifactId><executions><execution><phase>install</phase><goals><goal>copy-dependencies</goal></goals><configuration><outputDirectory>${project.build.directory}/lib</outputDirectory></configuration></execution></executions></plugin></plugins>
  1. 下载jar文件
  2. 将jar文件复制到项目文件夹
  3. 获取inteliJ想法Maven命令区
  4. 在命令下面键入

mvn安装:安装文件-Dfile=YOUR_JAR_FILE_LOCATION*JARNAME. jar-Dgroup pId=org.primefaces.themes-DartifactId=iMetro-Dversion=1.0.1-D包装=jar*


例子:

mvn安装:安装文件-Dfile=C:\用户\ranushka. l\桌面\测试\spring-web-1.0.2.jar-Dgroup pId=org.primefaces.themes-DartifactId=iMetro-Dversion=1.0.1-D包装=jar