mavendo -assembly-plugin MojoExecutionException与依赖项设置为outputDirectory。

时间:2022-09-08 02:50:41

In my Khatami project I'm using maven to both manage compilation and package up the result into a runnable artifact: executable shell-script at the top-level, bin/ containing the executable jar and its dependent jars. Please see what I mean here.

在我的Khatami项目中,我使用maven来管理编译并将结果打包成一个可运行的工件:顶层的可执行shell脚本,bin/包含可执行jar及其相关jar。请理解我的意思。

For reference, here's the salient part of Khatami's pom.xml:

作为参考,这里是哈塔米的主要部分。xml:

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/src.xml</descriptor>
          </descriptors>
          <archive>
            <manifest>
              <mainClass>${project.groupId}.Main</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>

and the full src/main/assembly/src.xml:

和完整的src /主/组装/ src.xml:

<assembly>
  <id>dist</id>
  <formats>
    <format>tar.gz</format>
  </formats>
  <dependencySets>
    <dependencySet>
      <outputDirectory>bin</outputDirectory>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>src/main/assembly</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>khatami</include>
      </includes>
      <fileMode>744</fileMode>
      <lineEnding>unix</lineEnding>
      <filtered>true</filtered>
    </fileSet>
  </fileSets>
</assembly>

and compilation attempt:

和编译的尝试:

$ mvn clean compile assembly:single
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building khatami 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ khatami ---
[INFO] Deleting /home/blt/projects/com/carepilot/repos/khatami/target
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ khatami ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/blt/projects/com/carepilot/repos/khatami/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ khatami ---
[INFO] Compiling 1 source file to /home/blt/projects/com/carepilot/repos/khatami/target/classes
[INFO] 
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (default-cli) @ khatami ---
[INFO] Reading assembly descriptor: src/main/assembly/src.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.721s
[INFO] Finished at: Mon Jul 18 13:58:30 EDT 2011
[INFO] Final Memory: 8M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (default-cli) on project khatami: Failed to create assembly: Error adding file 'com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT' to archive: /home/blt/projects/com/carepilot/repos/khatami/target/classes isn't a file. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Where am I at fault?

我有什么错?

2 个解决方案

#1


14  

The relevant part of the error information is

错误信息的相关部分是

Error adding file 'com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT' to archive:
/home/blt/projects/com/carepilot/repos/khatami/target/classes isn't a file.

it is expecting a file and it can't find it because the package goal isn't running after the clean .

它正在等待一个文件,但是它找不到它,因为包目标并没有在清理之后运行。

if you do mvn clean compile package assembly:single it will build successfully.

如果您执行mvn清理编译包组装:单个编译将成功构建。

I would add the assembly:single goal to the package phase, that way it will build automatically.

我将向包阶段添加assembly:单一目标,这样它将自动构建。

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <descriptors>
          <descriptor>src/main/assembly/src.xml</descriptor>
        </descriptors>
        <archive>
          <manifest>
            <mainClass>${project.groupId}.Main</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </execution>
  </executions>
</plugin>

with the above changes to the configuration you can just issue.

通过以上对配置的更改,您可以发布。

mvn clean package

and the assembly:single goal will be executed automatically.

程序集:将自动执行单个目标。

A better way to do this might be to use the maven-shade-plugin instead of doing this manually.

更好的方法可能是使用maven-shade-plugin,而不是手工操作。

#2


3  

Your problem:

你的问题:

Error adding file 'com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT' to archive:
/home/blt/projects/com/carepilot/repos/khatami/target/classes isn't a file.

Is caused because the project artifact (com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT) has not been packaged yet, but is part of the assembly's <dependencySet>. You can add <useProjectArtifact>false</useProjectArtifact> to your <dependencySet> to resolve the problem.

由于项目工件(com.carepilot.khatami:khatami:jar:1.0 snapshot)还没有被打包,但是它是程序集的 的一部分。您可以将 false 添加到您的 以解决问题。

If you need the project's class file included in the assembly, you can use a <fileSet> to include directory target/classes.

如果需要程序集中包含项目的类文件,可以使用 包含目录目标/类。

For example:

例如:

<assembly>
  <id>dist</id>
  <formats>
    <format>tar.gz</format>
  </formats>
  <dependencySets>
    <dependencySet>
      <useProjectArtifact>false</useProjectArtifact>
      <outputDirectory>bin</outputDirectory>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>src/main/assembly</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>khatami</include>
      </includes>
      <fileMode>744</fileMode>
      <lineEnding>unix</lineEnding>
      <filtered>true</filtered>
    </fileSet>
  </fileSets>
</assembly>

Another option would be to attach the assembly to a phase after packaging.

另一种选择是在包装后将程序集附加到一个阶段。

#1


14  

The relevant part of the error information is

错误信息的相关部分是

Error adding file 'com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT' to archive:
/home/blt/projects/com/carepilot/repos/khatami/target/classes isn't a file.

it is expecting a file and it can't find it because the package goal isn't running after the clean .

它正在等待一个文件,但是它找不到它,因为包目标并没有在清理之后运行。

if you do mvn clean compile package assembly:single it will build successfully.

如果您执行mvn清理编译包组装:单个编译将成功构建。

I would add the assembly:single goal to the package phase, that way it will build automatically.

我将向包阶段添加assembly:单一目标,这样它将自动构建。

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <descriptors>
          <descriptor>src/main/assembly/src.xml</descriptor>
        </descriptors>
        <archive>
          <manifest>
            <mainClass>${project.groupId}.Main</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </execution>
  </executions>
</plugin>

with the above changes to the configuration you can just issue.

通过以上对配置的更改,您可以发布。

mvn clean package

and the assembly:single goal will be executed automatically.

程序集:将自动执行单个目标。

A better way to do this might be to use the maven-shade-plugin instead of doing this manually.

更好的方法可能是使用maven-shade-plugin,而不是手工操作。

#2


3  

Your problem:

你的问题:

Error adding file 'com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT' to archive:
/home/blt/projects/com/carepilot/repos/khatami/target/classes isn't a file.

Is caused because the project artifact (com.carepilot.khatami:khatami:jar:1.0-SNAPSHOT) has not been packaged yet, but is part of the assembly's <dependencySet>. You can add <useProjectArtifact>false</useProjectArtifact> to your <dependencySet> to resolve the problem.

由于项目工件(com.carepilot.khatami:khatami:jar:1.0 snapshot)还没有被打包,但是它是程序集的 的一部分。您可以将 false 添加到您的 以解决问题。

If you need the project's class file included in the assembly, you can use a <fileSet> to include directory target/classes.

如果需要程序集中包含项目的类文件,可以使用 包含目录目标/类。

For example:

例如:

<assembly>
  <id>dist</id>
  <formats>
    <format>tar.gz</format>
  </formats>
  <dependencySets>
    <dependencySet>
      <useProjectArtifact>false</useProjectArtifact>
      <outputDirectory>bin</outputDirectory>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>src/main/assembly</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>khatami</include>
      </includes>
      <fileMode>744</fileMode>
      <lineEnding>unix</lineEnding>
      <filtered>true</filtered>
    </fileSet>
  </fileSets>
</assembly>

Another option would be to attach the assembly to a phase after packaging.

另一种选择是在包装后将程序集附加到一个阶段。