Maven在将JAR安装到存储库时不读取POM
我按照指南将JAR文件安装到本地存储库中 我运行以下命令:Maven在将JAR安装到存储库时不读取POM,maven,maven-3,pom.xml,maven-install-plugin,Maven,Maven 3,Pom.xml,Maven Install Plugin,我按照指南将JAR文件安装到本地存储库中 我运行以下命令: mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar JAR文件是使用Maven构建的,其中包含一个POM文件,列出了它的依赖项。JAR中的文件具有以下路径: /META-INF/maven/in.ksharma/log4j-weblayout/pom.xml Mav
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar
JAR文件是使用Maven构建的,其中包含一个POM文件,列出了它的依赖项。JAR中的文件具有以下路径:
/META-INF/maven/in.ksharma/log4j-weblayout/pom.xml
Maven安装工件,但不读取其POM。它会创建一个空POM文件,其中没有任何依赖项信息:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>in.ksharma</groupId>
<artifactId>log4j-weblayout</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>POM was created from install:install-file</description>
</project>
/META-INF/maven/in.ksharma/log4j weblayout/pom.properties
:
#Generated by Maven
#Wed Oct 08 19:48:28 IST 2014
version=0.0.1-SNAPSHOT
groupId=in.ksharma
artifactId=log4j-weblayout
/META-INF/maven/in.ksharma/log4j weblayout/pom.xml
:
<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>
<groupId>in.ksharma</groupId>
<artifactId>log4j-weblayout</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<url>https://github.com/Kshitiz-Sharma/log4j-weblayout</url>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<!-- Compile dependencies -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>joor</artifactId>
<version>0.9.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
<!-- Provided dependencies -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.5.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.1.8</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
4.0.0
伊恩哈马
log4j网络布局
0.0.1-快照
罐子
https://github.com/Kshitiz-Sharma/log4j-weblayout
1.6
1.6
org.apache.velocity
速度
1.7
编译
org.jooq
乔尔
0.9.3
编译
公地io
公地io
2.4
编译
log4j
log4j
1.2.16
假如
org.springframework
弹簧芯
4.0.5.1发布
测试
org.codehaus.groovy
groovy all
2.1.8
测试
我认为您需要从jar中提取pom.xml,并使用以下命令指定它:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar -DpomFile=pom.xml
似乎是(2015年1月),
尽管最新版本(2014年8月27日发布的版本2.5.2)中没有该修复程序,似乎在3.0.0-M1版本的install plugin中得到了修复,但maven可能仍然默认使用2.5.2。您可以在插件管理部分设置安装插件的版本:
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
...
</plugins>
</pluginManagement>
你能把pom的内容发布到jar里吗?@AndrésMongeMoreno请看我的编辑。问题是:你有一个可以用来构建工件的pom……为什么不简单地做:
mvn install
?@khmarbaise如果我想把构建的jar而不是代码分发给另一个用户呢?如果你做了一个安装,它会准确地安装仅将jar文件保存到本地存储库中。那么这里有什么问题?(要明确的是,jar文件可以简单地提取,类文件可以反编译)…我看不出有什么问题?我认为没有必要这样做。文档说明如果JAR是由Apache Maven构建的,它将在META-INF目录的子文件夹中包含一个pom.xml,默认情况下将读取该文件。
我在安装文件目标的文档中没有看到这一点:。有几个选项说明可以从包含的pom.xml中提取groupId、artifactId和version,但我看不到您在此处复制的句子。该句子是从问题中提供的中复制的。这是正确答案。尽管Maven Install插件应该能够在JAR中使用pom,但joanpau已经提到的当前版本(2.5.2)有一个漏洞,并且没有这样做。理论上,这个漏洞已经修复,修复版本是3.0.0,但是一年后我仍然在3.3.3中看到相同的问题。我在3.5.2.6+年后看到相同的错误,这仍然是3.6.3中的问题。我猜这是因为@JensViebig在回答中说了什么。为什么Maven仍然默认使用带有此bug的Maven安装插件版本?!?我在已经链接到的文档中看到插件版本已经更新,但没有更新。:'(我也希望有人提到应该检查安装在本地存储库中的pom.xml
是否正确。我花了比我愿意承认的更长的时间来确定这是缺少依赖项问题的根本原因。人们通常只安装包含各自依赖项的JAR吗它们,或者我遗漏了什么?另一个页面显示了install file
命令,几乎没有其他信息。
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
...
</plugins>
</pluginManagement>
mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar