我已经定义了一个个性化的jar-with-dependencies程序集描述符。但是,当我使用mvn assembly:assembly执行它时,我得到:
...
[INFO] META-INF/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] javax/ already added, skipping
[INFO] META-INF/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] META-INF/maven/ already added, skipping
[INFO] [assembly:assembly {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error reading assemblies: No assembly descriptors found.
我的 jar-with-dependencies.xml 位于 src / main / resources / assemblies / 中。
我的汇编描述符如下:
<?xml version='1.0' encoding='UTF-8'?>
<assembly>
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<dependencySets>
<dependencySet>
<scope>runtime</scope>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<exclude>**/LICENSE*</exclude>
<exclude>**/README*</exclude>
</excludes>
</unpackOptions>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>src/main/resources/META-INF/services</directory>
<outputDirectory>META-INF/services</outputDirectory>
</fileSet>
</fileSets>
</assembly>
我的项目pom.xml是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>jar-with-dependencies.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>org.my.app.HowTo</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
当执行mvn assembly:assembly时,会解压缩依赖项,并在解压缩完成后得到上一个错误。
此外,如果我执行mvn -e assembly:assembly,则说没有找到描述符,但是它尝试解包依赖关系并创建了一个带依赖关系的JAR,但它不包含META-INF / services / *如描述符中所指定的那样:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error reading assemblies: No assembly descriptors found.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error reading assemblies: No assembly descriptors found.
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error reading assemblies: No assembly descriptors found.
at org.apache.maven.plugin.assembly.mojos.AbstractAssemblyMojo.execute(AbstractAssemblyMojo.java:356)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by: org.apache.maven.plugin.assembly.io.AssemblyReadException: No assembly descriptors found.
at org.apache.maven.plugin.assembly.io.DefaultAssemblyReader.readAssemblies(DefaultAssemblyReader.java:206)
at org.apache.maven.plugin.assembly.mojos.AbstractAssemblyMojo.execute(AbstractAssemblyMojo.java:352)
... 19 more
我没有看到我的错误。有人有解决方案吗?
答案 0 :(得分:22)
这里有两个问题。首先,在使用您自己的描述符时,您必须指定自定义描述符文件的路径(顺便说一下,您可以使用任何位置,但将描述符放在src/main/resources
中可能不是最好的选择,你真的不希望在你的应用程序中打包描述符,我会使用this page中提到的标准位置src/main/assembly
。
<descriptors>
<descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
</descriptors>
其次,您的configuration
元素当前位于execution
块内,因此特定于此执行。换句话说,如果在命令行上运行assembly:assembly
,它将不适用。因此,如果您想使用自定义描述符调用assembly:assembly
,请使用:
mvn assembly:assembly -Ddescriptor=path/to/descriptor.xml
或者将configuration
移到execution
元素之外(以使配置成为全局):
<project>
...
<build>
...
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptors>
<descriptor>path/to/descriptor.xml</descriptor>
</descriptors>
...
</configuration>
</plugin>
</plugins>
...
</build>
...
</project>
答案 1 :(得分:4)
程序集正试图在类路径中打开/assemblies/${ref}.xml 检查一下