繁体   English   中英

Maven的依赖插件以错误的方式复制罐子

[英]maven-dependency-plugin copies jars in a wrong way

在我的本地存储库( .m2/repository )中,我有几个jar,我希望将它们复制到我的项目中(并引用)。 对于com.google.protobuf工件,我具有以下pom.xml

<?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>
   <parent>
      <groupId>groupName</groupId>
      <artifactId>groupName.master</artifactId>
      <relativePath>../pom.xml</relativePath>
      <version>1.0.0-SNAPSHOT</version>
   </parent>
   <groupId>groupName</groupId>
   <artifactId>com.google.protobuf</artifactId>
   <name>com.google.protobuf</name>
   <version>2.5.0</version>
   <build>
   <plugins>
   <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.10</version>
          <executions>
            <execution>
              <id>copy-installed</id>
              <phase>install</phase>
              <goals>
                <goal>copy</goal>
              </goals>
              <configuration>
                <artifactItems>
                  <artifactItem>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>${project.artifactId}</artifactId>
                    <version>${project.version}</version>
                    <type>${project.packaging}</type>
                  </artifactItem>
                </artifactItems>
                <outputDirectory>build</outputDirectory>
              </configuration>
            </execution>
          </executions>
        </plugin>
     </plugins>
   </build>
</project>

基本上,我希望此插件将必要的jar文件复制到名为build的文件夹,该文件夹位于模块文件夹本身下。 确实复制了一个罐子。 但是,当我单击并打开罐子时,看不到任何文件,只有清单。 因此,参考文献显然给出了错误。 我检查了本地存储库,然后找到了罐子,并且罐子的格式正确。 因此,源头不是问题。 复制过程出了点问题。

这是同一人工制品的罐子。 一种是从本地存储库中获取的(上面),另一种是所谓的复制到build文件夹中。 如您所见,复制的文件缺少在com文件夹下找到的类文件。

在此处输入图片说明

为什么插件会复制不正确? 任何人都有类似的经历吗?

更新:我注意到的一件事是,这两个jar里面都有不同的MANIFEST文件。 是否可能是这样的情况:其中一个罐子不应该从某个地方取走?

好,知道了 问题是我以错误的方式定义了工件。 应该是:

                  <artifactItem>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>${project.artifactId}</artifactId>
                    <version>${project.version}</version>
                    <overWrite>true</overWrite>
                    <type>${project.packaging}</type>
                    <outputDirectory>build</outputDirectory>
                    <destFileName>protobuf-java-2.5.0.jar</destFileName>
                  </artifactItem>

注意<name >标记,这在我的pom.xml是不正确的,因此系统无法捕获必要的工件。 也是destFileName标记。

另外,在上面,这是错误的:

<groupId>groupName</groupId>
<artifactId>com.google.protobuf</artifactId>
<name>com.google.protobuf</name>

如果要使用从中央存储库下载的版本,则不能更改groupIdartifactId 他们应该留在包裹的网站上。

修复这些问题后,现在可以看到类文件。

添加此插件pox.xml

<plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-appCtx</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <!--copy location-->
                            <outputDirectory>src/main/resources</outputDirectory>
                            <overwrite>true</overwrite>
                            <resources>
                                <resource>
                                    <!--file location-->
                                    <directory>${basedir}/lib</directory>
                                    <includes>
                                        <include>test1.jar</include>
                                        <include>test2.jar</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

暂无
暂无

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

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