Maven 通过 pom 安装外部 jar 不起作用 [英] Maven install external jar through pom not working
问题描述
我想在我的项目中添加一个外部 jar.我想将它添加到 pom 中而不是通过 maven 命令安装它.
I want to add a an external jar to my project. I want to add it inside the pom instead of installing it via the maven command.
这是我在 pom 中配置的内容:
This is what I have configured inside my pom:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<repositoryLayout>default</repositoryLayout>
<groupId>org.opencv</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0</version>
<packaging>jar</packaging>
<file>${project.basedir}/../runtime-resources/opencv-dep/opencv-320.jar</file>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
我收到此错误:缺少org.opencv:opencv:jar:3.2.0的POM,没有可用的依赖信息.
但是当运行命令时,一切正常:mvn install:install-file -Dfile={absolute-path-to-jar}/opencv-320.jar -DgroupId=org.opencv-DartifactId=opencv -Dversion=3.2.0 -Dpackaging=jar
But when running the command, everything is oke:
mvn install:install-file -Dfile={absolute-path-to-jar}/opencv-320.jar -DgroupId=org.opencv
-DartifactId=opencv -Dversion=3.2.0 -Dpackaging=jar
注意:这仅适用于 Netbeans,而不适用于 InteliJ.Netbeans 显然跳过了安装命令,只是在线搜索依赖项,当然找不到它.我跑了 mvn install
mvn install:install
mvn install:install-file
NOTE: This is only the case on Netbeans and not on InteliJ. Netbeans apparently skips the install command and just searches for the dependency online, and ofcourse can't find it. I ran mvn install
mvn install:install
mvn install:install-file
推荐答案
回答这个问题:Maven 安装插件:参数文件丢失或无效
将
更改为
并使用 mvn initialize
运行.它解决了我在 Netbeans 上的问题.
Change <phase>install</phase>
to <phase>initialize</phase>
and run with mvn initialize
. And it solved my problem on Netbeans.
这篇关于Maven 通过 pom 安装外部 jar 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!