使用maven创建一个zip文件

时间:2014-08-08 10:06:52

标签: java maven-2 maven-assembly-plugin

我正在尝试使用程序集插件来为多模块Maven项目的特定模块创建一个zip文件。 这个模块只包含一堆需要打包为zip文件的xml和xsl文件(文件夹的结构保存在src / main / resources下)。

所以我在下面创建了pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <parent>
<groupId>foo.bar</groupId>
<artifactId>myserver</artifactId>
<version>${myserver.version}</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>foo.bar</groupId>
  <artifactId>zip-sample</artifactId>
  <name>Sample zip</name>
  <version>${myserver.version}</version>
  <build>
<plugins>
  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
      <execution>
    <configuration>
      <descriptorRefs>
        <descriptorRef>bin</descriptorRef>
      </descriptorRefs>
    </configuration>
    <id>create-distribution</id>
    <phase>package</phase>
    <goals>
      <goal>single</goal>
    </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
  </build>
</project>

但是我收到了错误:

[DEBUG] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Unable to build project for plugin 'org.apache.maven.plugins:maven-assembly-plugin': Not a v4.0.0 POM. for project org.apache.maven.plugins:maven-assembly-plugin at /home/gundam/.m2/repository/org/apache/maven/plugins/maven-assembly-plugin/2.3/maven-assembly-plugin-2.3.pom
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(DefaultLifecycleExecutor.java:1557)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.bindPluginToLifecycle(DefaultLifecycleExecutor.java:1503)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.constructLifecycleMappings(DefaultLifecycleExecutor.java:1282)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:534)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    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.InvalidPluginException: Unable to build project for plugin 'org.apache.maven.plugins:maven-assembly-plugin': . for project org.apache.maven.plugins:maven-assembly-plugin at /home/gundam/.m2/repository/org/apache/maven/plugins/maven-assembly-plugin/2.3/maven-assembly-plugin-2.3.pom
    at org.apache.maven.plugin.DefaultPluginManager.checkRequiredMavenVersion(DefaultPluginManager.java:293)
    at org.apache.maven.plugin.DefaultPluginManager.verifyVersionedPlugin(DefaultPluginManager.java:205)
    at org.apache.maven.plugin.DefaultPluginManager.verifyPlugin(DefaultPluginManager.java:184)
    at org.apache.maven.plugin.DefaultPluginManager.loadPluginDescriptor(DefaultPluginManager.java:1642)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(DefaultLifecycleExecutor.java:1540)
    ... 18 more
Caused by: org.apache.maven.project.InvalidProjectModelException: Not a v4.0.0 POM. for project org.apache.maven.plugins:maven-assembly-plugin at /home/gundam/.m2/repository/org/apache/maven/plugins/maven-assembly-plugin/2.3/maven-assembly-plugin-2.3.pom
    at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1599)
    at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1571)
    at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:562)
    at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromRepository(DefaultMavenProjectBuilder.java:251)
    at org.apache.maven.plugin.DefaultPluginManager.checkRequiredMavenVersion(DefaultPluginManager.java:277)
    ... 22 more

我试图更改程序集插件版本,但即使pom似乎没问题,我也总是出现“Not a v4.0.0 POM”错误。

Maven的版本使用:

$ mvn -v
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.6.0_20
Java home: /usr/lib/jvm/jdk1.6.0_20/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "3.11.0-12-generic" arch: "amd64" Family: "unix"

pom.xml中的插件定义可能有问题吗?

1 个答案:

答案 0 :(得分:1)

特定的POM文件是否可能损坏或损坏?你能看一下以下内容:/home/gundam/.m2/repository/org/apache/maven/plugins/maven-assembly-plugin/2.3/maven-assembly-plugin-2.3.pom

请点击此处What does this mean: Not a v4.0.0 POM. for project org.codehaus.mojo:rpm-maven-plugin,其中有人遇到类似问题。