gpt4 book ai didi

java - maven-assembly-plugin MojoExecutionException 与 dependencySet 作为 outputDirectory

转载 作者:搜寻专家 更新时间:2023-10-30 21:21:53 31 4
gpt4 key购买 nike

在我的Khatami项目 我正在使用 maven 来管理编译并将结果打包到一个可运行的 Artifact 中:顶层的可执行 shell 脚本,bin/ 包含可执行 jar 及其依赖的 jar。请看我的意思here .

作为引用,这里是 Khatami 的 pom.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>

和完整的src/main/assembly/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>

和编译尝试:

$ 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

我错在哪里?

最佳答案

错误信息的相关部分是

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.

它需要一个文件,但找不到它,因为 package 目标没有在 clean 之后运行。

如果你执行 mvn clean compile package assembly:single 它将成功构建。

我会将 assembly:single 目标添加到 package 阶段,这样它将自动构建。

<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>

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

mvn clean package

assembly:single 目标将自动执行。

执行此操作的更好方法可能是使用 maven-shade-plugin而不是手动执行此操作。

关于java - maven-assembly-plugin MojoExecutionException 与 dependencySet 作为 outputDirectory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6737221/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com