如何直接在项目的库源中添加本地 jar 文件(还不是 Maven 存储库的一部分)?
install-file
脚本。
您可以像这样直接添加本地依赖项(如 build maven project with propriatery libraries included 中所述):
<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 group 提出了关于此 https://issues.apache.org/jira/browse/MNG-6523 的问题(您可以参与并描述此功能在某些情况下有用的原因)。我希望这个功能仍然存在!
如果您问我,只要不删除该功能,我就会使用它来仅依赖我的项目中一个不适合存储库的顽皮 jar 文件。如果去掉这个功能,好吧,这里有很多好的答案,我以后可以从中选择!
将 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
参考
Maven 常见问题解答:我有一个想要放入本地存储库的 jar。怎么复制进去?
Maven 安装插件用法: install:install-file 目标
首先,我想将这个答案归功于一个匿名的 Stack Overflow 用户——我很确定我以前在这里看到过类似的答案——但现在我找不到了。
将本地 JAR 文件作为依赖项的最佳选择是创建本地 Maven 存储库。这样的存储库只不过是一个适当的目录结构,其中包含 pom 文件。
对于我的示例:我的主项目位于 ${master_project}
位置,而 subproject1 位于 ${master_project}/${subproject1}
。
然后我在 ${master_project}/local-maven-repo
中创建一个 Maven 存储库。
在位于 ${master_project}/${subproject1}/pom.xml
的 subproject1 中的 pom 文件中,需要指定将文件路径作为 URL 参数的存储库:
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file:///${project.parent.basedir}/local-maven-repo</url>
</repository>
</repositories>
可以为任何其他存储库指定依赖项。这使您的 pom 存储库独立。例如,一旦所需的 JAR 在 Maven 中心可用,您只需从本地存储库中删除它,它将从默认存储库中提取。
<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 存储库可以提交到代码存储库,并且整个设置与系统无关。 (Working example in GitHub)。
我同意将 JAR 提交到源代码 repo 不是一个好习惯,但在现实生活中,快速而肮脏的解决方案有时比一个完整的 Nexus repo 更好地托管一个您无法发布的 JAR。
${project.parent.basedir}
现在似乎无法解决任何问题,因此我使用了 ${project.basedir}/..
并且效果很好。
<mirrorOf>*</mirrorOf>
镜像。
在 Maven 项目的根目录下创建一个新文件夹,例如 local-maven-repo
。
只需在 pom.xml
的 <project>
中添加一个本地存储库:
<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]
local-maven-repo
包含在您的源文件夹中(在此示例中为子文件夹)
我想要这样的解决方案 - 在 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 repo 中。现在这个 jar 在这台机器上的任何 maven 步骤中都可用(不要忘记在 pom 中包含这个依赖项作为带有 <dependency></dependency>
标记的任何其他 maven 依赖项)。也可以不将 jar install 绑定到 initialize
步骤,而是绑定到您喜欢的任何其他步骤。
mvn package
之前运行 mvn initialize
:我不能 mvn initialize package
否则它会尝试从中央存储库下载 JAR。为什么是这样?我认为它会按顺序运行这个目标/阶段。
compile
),则构建将失败。
真正快速而肮脏的方法是指向本地文件,请注意“系统”现在已弃用:
<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/artifactory)通常是有意义的,或者如果您没有这些存档或不想设置一个本地 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>
对于这个解决方案,相对路径也可以使用 basedir 变量:
<url>file:${basedir}</url>
<url>file:${basedir}</url>
作为基本网址。
<scope>system
已弃用。
<dependency>
<groupId>group id name</groupId>
<artifactId>artifact name</artifactId>
<version>version number</version>
<scope>system</scope>
<systemPath>jar location</systemPath>
</dependency>
<scope>system
现在已弃用。
install:install-file
中提到的,将工件添加到本地 repo 并将其用作“正常”依赖项(具有默认范围 compile
)或使用 in-project repository solution。
依赖的重要部分是:${pom.basedir}(而不仅仅是 ${basedir})
<dependency>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/src/lib/example.jar</systemPath>
</dependency>
<scope>system
已弃用。
在 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 中:
https://i.stack.imgur.com/ywD6y.png
第 1 步:在您的 pom.xml
中使用目标 install-file
配置 maven-install-plugin
<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
文件夹放在您的项目中以便使用项目特定的相对路径,避免添加系统特定的绝对路径。
如果您有多个外部 jar,只需对同一 maven-install-plugin
中的其他 jar 重复 <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 存储库。而已。它不会自动将这些 jars 作为 maven 依赖项包含到您的项目中。
这是一个小问题,但有时很容易错过。
mvn compile
并且如果在构建之前没有 mvn clean
将失败,则没有 <phase>clean
。
一种方法是将其上传到您自己的 Maven 存储库管理器(例如 Nexus)。无论如何,拥有自己的存储库管理器是一种很好的做法。
我最近看到的另一种好方法是在构建生命周期中包含 Maven 安装插件:您在 POM 中声明将文件安装到本地存储库。这是一个很小但很小的开销,并且不涉及手动步骤。
http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html
当然,您可以将 jars 添加到该文件夹中。但也许它不是你想要实现的......
如果您需要这些 jar 进行编译,请检查以下相关问题:Can I add jars to maven 2 build classpath without installing them?
此外,在任何人建议之前,不要使用系统范围。
另一个有趣的案例是当你想在你的项目中拥有私有的 maven jars。您可能希望保留 Maven 的功能来解决传递依赖关系。解决方案相当简单。
在您的项目中创建一个文件夹 libs 在您的 pom.xml 文件中添加以下行
例如,假设您要导入依赖项
<dependency>
<groupId>com.mycompany.myproject</groupId>
<artifactId>myproject</artifactId>
<version>1.2.3</version>
</dependency>
只需继续 .m2/repository ,您将看到以下文件夹
com/mycompany/myproject/1.2.3
复制 libs 文件夹中的所有内容(同样,包括 .m2/repository 下的文件夹),您就完成了。
命令行 :
mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code
-DartifactId=kaptcha -Dversion={version} -Dpackaging=jar
将本地 jar 库、它们的源代码和 javadoc 添加到 Maven 项目
如果您使用库、它们的 sources
和 javadoc
预编译了 jar
文件,那么您可以将它们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-install-plugin 用法。
或者,您可以使用 maven-source-plugin 和 maven-javadoc-plugin 自己build
这些库及其 sources
和 javadoc
,然后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.0
http://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>
执行 maven install
目标:
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>
我认为解决此问题的更好方法是使用 maven-install-plugin 在安装时自动安装文件。这就是我为我的项目设置它的方式。
首先,将路径(存储本地 .jars 的位置)添加为属性。
<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>
最后,在依赖项中,您可以添加罐子
<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 install
或 mvn test
时,将自动添加本地 jar。
这是较新版本的简短语法:
mvn install:install-file -Dfile=<path-to-file>
当 JAR 由 Apache Maven 构建时它可以工作——最常见的情况。然后它将在 META-INF 目录的子文件夹中包含一个 pom.xml,默认情况下会读取该文件。
来源:http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
我想分享一个代码,您可以在其中上传一个装满 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 directory
PrintWriter 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。
String symbolicName = attributes.getValue("Bundle-SymbolicName"); if(symbolicName!=null &&symbolicName.contains("com.yourCompany.yourProject"))
似乎表明仅支持 custom jar。这不是我们需要的:而是一堆第三方罐子。您对如何以这种方式安装 any jar 有什么建议吗?
创建一个本地 Maven 存储库目录,您的项目根目录应如下所示:
yourproject
+- pom.xml
+- src
为组 com.example 和版本 1.0 添加一个名为 repo 的标准 Maven 存储库目录:
yourproject
+- pom.xml
+- src
+- repo
将工件部署到存储库中,Maven 可以使用 mvn deploy:deploy-file 目标为您部署工件:
mvn deploy:deploy-file -Durl=file:///pathtoyour/repo -Dfile=your.jar -DgroupId=your.group.id -DartifactId=yourid -Dpackaging=jar -Dversion=1.0
安装与您的 jar 对应的 pom 文件,以便您的项目可以在本地 repo 的 maven 构建期间找到 jar:
mvn install:install-file -Dfile=/path-to-your-jar-1.0.jar -DpomFile=/path-to-your-pom-1.0.pom
在你的 pom 文件中添加 repo:
<repositories>
<!--other repositories if any-->
<repository>
<id>project.local</id>
<name>project</name>
<url>file:${project.basedir}/repo</url>
</repository>
</repositories>
在你的 pom 中添加依赖项:
<dependency>
<groupId>com.groupid</groupId>
<artifactId>myid</artifactId>
<version>1.0</version>
</dependency>
要安装第三方 jar,请调用如下命令
mvn install:install-file -DgroupId= -DartifactId= -Dversion= -Dpackaging=jar -Dfile=path
出于某种原因,在我进行维护的 Web 应用程序中,Alireza Fattahi's solution 和 JJ Roman's solution 都不能正常工作。在这两种情况下,编译都正常(它看到了 jar),但打包未能将 jar 包含在 war 中。
我设法使它工作的唯一方法是将罐子放在 /src/main/webapp/WEB-INF/lib/
上,然后将它与 Fattahis 或 Roman 的解决方案结合起来。
不是原始问题的答案,但它可能对某人有用
没有使用 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 folder
implementation name: 'akka-protobuf-v3_2.12-2.6.1'
implementation name: 'akka-stream_2.12-2.6.1'
}
请注意,使用本地存储库不一定是个好主意。如果这个项目与其他人共享,那么其他人在它不起作用时都会遇到问题和疑问,并且即使在您的源代码控制系统中也无法使用该 jar!
尽管共享 repo 是最好的答案,但如果由于某种原因你不能这样做,那么嵌入 jar 比本地 repo 更好。仅限本地的 repo 内容可能会导致很多问题,尤其是随着时间的推移。
在本地存储库中,您可以通过发出命令来安装 jar
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
按照这个有用的 link 从 mkyoung 的网站做同样的事情。您还可以查看 maven guide for the same
mvn 安装
您可以在命令行中编写下面的代码,或者如果您使用 eclipse 内置 maven 右键单击项目 -> 运行方式 -> 运行配置... -> 在左侧面板中右键单击 Maven 构建 -> 新配置 -> 编写目标和基目录中的代码:${project_loc:NameOfYourProject} -> 运行
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
其中每个指的是:
< artifact-id >:文件的工件名称 eg -> kaptcha
2.安装后,只需在pom.xml中声明jar即可。
<dependency>
<groupId>com.google.code</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3</version>
</dependency>
也许有人会对:https://github.com/Limraj/maven-artifact-generator
控制台程序,用于在本地存储库中生成 maven 工件,并根据 jar 的路径为 pom.xml 配置依赖项。您可以对一个文件执行此操作,但如果您有多个 jar 文件,它最有用。
路径罐子:java -jar maven-artifact-generator-XXXjar -p path_to_jars -g com.test -V 1.2.3 -P jar
jar: java -jar maven-artifact-generator-XXXjar -f file_jar -g com.test -V 1.2.3 -P jar
这将在本地 maven 存储库中生成一个工件,并在 gen.log 中为 pom.xml 生成依赖项。 ArtifactId 是 jar 文件的名称。
需要已安装的 Maven。在 widnows 7 和 macOS X (unix/linux) 上进行测试。
我的 pom.xml 中的一组依赖项出现了相同的错误,结果是 pom.xml 中没有指定依赖项的版本,并且在父存储库中提到了这些版本。由于某种原因,版本详细信息未与此 repo 同步。因此,我使用标签手动输入了版本,它就像一个魅力。在父项中查找版本并在此处指定需要一点时间。但这仅适用于显示 artifactid 错误的 jar 并且有效。希望这可以帮助某人。
在 Apache Maven 3.5.4 中,我不得不添加双引号。没有双引号,它对我不起作用。
例如: mvn install:install-file "-Dfile=位置到 jar 文件" "-DgroupId=group id" "-DartifactId=artifact id" "-Dversion=version" "-Dpackaging=package type"
不定期副业成功案例分享
artifactId
和groupId
不是错误的方式吗?