maven-dependency-plugin 以错误的方式复制 jar

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 的文件夹中,该文件夹位于模块文件夹本身下。它有点复制一个罐子。但是,当我单击并打开 jar 时,我看不到任何文件,只有清单。所以参考文献显然给出了错误。我检查了我的本地存储库,jar 在那里,并且格式正确。所以来源不是问题。复制过程出了点问题。

这是同一神器的罐子。一个取自本地存储库(上方),另一个是所谓的复制到 build 文件夹。如您所见,复制的文件缺少 com 文件夹下的 class 文件。

为什么插件复制不正确?有人有过类似经历吗?

更新: 我注意到的一件事是这两个罐子里面有不同的 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。它们应该保持在包裹网站上给出的样子。

修复这些后,现在我可以看到 class 个文件了。

添加这个插件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>