Java 创建程序集存档箱时出错:您必须至少设置一个文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33852914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:05:18  来源:igfitidea点击:

Error creating assembly archive bin: You must set at least one file

javamavenmaven-assembly-plugin

提问by Program-Me-Rev

I have a maven multi-module project with a module called mod1that I'm trying to add into a folder /project jarswith mvn assembly:assemblyfrom the app folder, where the app pom.xml is.

我有一个模块调用一个Maven多模块项目MOD1,我试图添加到一个文件夹/project jarsmvn assembly:assembly从应用程序文件夹,其中的应用程序pom.xml的是。

error:

错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.3:single (assembly) on project wrapper: Failed to create assembly
: Error creating assembly archive bin: You must set at least one file. -> [Help 1]

Project folder structure:

项目文件夹结构:

app
    | pom.xml
    | src    | main     | ...
wrapper
    | pom.xml
    | src    | main     | ...
mod1
    | pom.xml
    | src    | main     | ...

// After mvn assembly:assembly

project jars
    | mod1.jar

mod1 pom.xml

mod1 pom.xml

<project>
  <groupId>org.test</groupId>
  <artifactId>mod1</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
</project>

wrapper pom.xml

包装 pom.xml

<groupId>org.test.app</groupId>
<artifactId>wrapper</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.3</version>
      <executions>
        <execution>
          <id>assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <descriptors>
              <descriptor>src/main/assembly/modules-assembly.xml</descriptor>
            </descriptors>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

The descriptor (src/main/assembly/modules-assembly.xml) :

描述符 ( src/main/assembly/modules-assembly.xml) :

<assembly>
    <id>bin</id>
    <baseDirectory>/</baseDirectory>

    <formats>
        <format>zip</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <moduleSets>
        <moduleSet>
            <useAllReactorProjects>true</useAllReactorProjects>
            <includes>
                <include>org.test:mod1.jar</include>
            </includes>
            <binaries>
                <attachmentClassifier>jar-with-dependencies</attachmentClassifier>
                <outputDirectory>/project jars</outputDirectory>
                <unpack>false</unpack>
            </binaries>
        </moduleSet>
    </moduleSets>
</assembly>

UPDATE

更新

app pom.xml

应用程序 pom.xml

<project>
  <groupId>org.test</groupId>
  <artifactId>app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <modules>
    <module>../mod1</module>
    <module>../wrapper</module>
  </modules>
</project>

回答by question_maven_com

Why you declare in the project 'app' the both modules 'wrapper' and 'mod1'. app must use 'mod1' at dependency lib?

为什么你在项目“app”中声明了两个模块“wrapper”和“mod1”。应用程序必须在依赖项库中使用“mod1”?

Do this :

做这个 :

Add parent pom.xml and 3 modules :
    +app
    +wrapper
    +mod1

pom app :

pom 应用程序:

<dependency>
 <groupId>${groupId}</groupId>
 <artifactId>mod1</artifactId> 
</dependency>

<plugin>  
 <groupId>org.apache.maven.plugins</groupId>  
 <artifactId>maven-jar-plugin</artifactId>   
 <configuration>  
  <archive>   
   <manifest>  
    <addClasspath>true</addClasspath>   
    <classpathPrefix>project/</classpathPrefix>  
  </manifest>  
</archive>  
</configuration>  
</plugin>

Create assembly.xml and filter dependency with <includes>and <excludes>.

创建assembly.xml与过滤器的依赖<includes><excludes>

To create the assembly, use this answer : Maven build assembly with dependencies

要创建程序集,请使用以下答案: Maven build assembly with dependencies

回答by Pichitron

Check your project structure. In my case the name of the directory that I was referencing with variables ($) was not correct,the directories were called differently and produced this error. I had to follow the error from the parent pom, going through the child, and config.xml.

检查您的项目结构。在我的情况下,我使用变量 ($) 引用的目录名称不正确,目录的调用方式不同并产生了此错误。我必须遵循来自父 pom 的错误,通过孩子和 config.xml。