Java maven程序集插件MojoExecutionException,dependencySet作为outputDirectory
在我的项目中,我使用maven管理编译并将结果打包成可运行工件:顶层的可执行shell脚本,Java maven程序集插件MojoExecutionException,dependencySet作为outputDirectory,java,maven,maven-assembly-plugin,Java,Maven,Maven Assembly Plugin,在我的项目中,我使用maven管理编译并将结果打包成可运行工件:顶层的可执行shell脚本,bin/,包含可执行jar及其依赖jar。请明白我的意思 作为参考,以下是哈塔米作品的突出部分: 和编译尝试: $ mvn clean compile assembly:single [INFO] Scanning for projects... [INFO]
bin/
,包含可执行jar及其依赖jar。请明白我的意思
作为参考,以下是哈塔米作品的突出部分:
和编译尝试:
$ 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.
它需要一个文件,但找不到它,因为包
目标在清理
后没有运行
如果您执行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>
并且将自动执行assembly:single
目标
<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>
更好的方法是使用,而不是手动操作。您的问题:
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.
是因为项目工件(com.careppilot.khatami:khatami:jar:1.0-SNAPSHOT)尚未打包,而是程序集的
的一部分。您可以将false
添加到
以解决问题
如果需要在程序集中包含项目的类文件,可以使用
来包含目录目标/类
例如:
<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>
距离
tar.gz
假的
箱子
src/主/总成
/
哈塔米
744
unix
真的
另一个选项是在打包后将程序集附加到阶段
编辑:
当在Maven构建设置中启用解析工作区工件时,我在Eclipse中也看到了这个问题。您如何运行Maven构建?从命令行或IDE>命令行内部。最后一个代码清单包含相关行,以$
开头。您是否曾在eclipse中使用过此项目,并使用一些插件将其导入eclipse环境中。这看起来像是maven的配置问题。我曾经遇到过这样的问题,我跟踪到了我的m2eclipse插件。(顺便说一句)不,恐怕不行。我不使用任何IDE。
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.
<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>