如何在maven中仅部署zip工件

时间:2014-08-22 07:21:43

标签: maven maven-plugin maven-deploy-plugin

我使用下面的描述符和pom文件在maven中完成了一些zip包装。但是在默认情况下,它在目标文件夹中创建了jar和zip。现在我想在我使用deploy:deploy-file插件的地方只部署zip内容。但它没有部署而是显示错误。不确定标签有什么问题以及应该如何解决。

Pom文件:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.wyndhamvo.prototype.dbscripts</groupId>
  <artifactId>DB_SCRIPTS</artifactId>
  <version>2.0.0.1</version>


<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptor>src/assembly/descriptor.xml</descriptor>
            </configuration>
            <executions> 
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <distributionManagement>
    <snapshotRepository>
        <id>wvoNexus</id>
        <file>${project.artifactId}-${project.version}.zip</file>
        <url>http://nexus.corproot.com/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>

    <repository>
        <id>wvoNexus</id>
        <file>${project.artifactId}-${project.version}.zip</file>
        <url>http://nexus.corproot.com/nexus/content/repositories/releases/</url>
    </repository>
  </distributionManagement>

</project>

程序集插件描述符文件:

<assembly>
<formats>
    <format>zip</format>
</formats>

<fileSets>
    <fileSet>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*</include>
        </includes>
        <outputDirectory>DB_Files</outputDirectory>
    </fileSet>
</fileSets>
</assembly>

执行命令:

mvn -X clean package deploy:deploy-file

错误:

[ERROR] Malformed POM C:\Divakar\MavenPrototype\DB_Maven_Test\dev\pom.xml: Unrecognised tag: 'file' (position: START_TAG seen ...<id>wvoNexus</id>\r\n\t\t\t<file>... @37:10)  @ C:\Divakar\MavenPrototype\DB_Maven_Test\dev\pom.xml, line 37, column 10

2 个答案:

答案 0 :(得分:6)

首先,您必须在分发管理区域修复错误,如下所示:

  <distributionManagement>
    <snapshotRepository>
        <id>wvoNexus</id>
        <url>http://nexus.corproot.com/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>

    <repository>
        <id>wvoNexus</id>
        <url>http://nexus.corproot.com/nexus/content/repositories/releases/</url>
    </repository>
  </distributionManagement>

如果您已修复,可以通过以下方式将文件简单地部署到nexus:

mvn clean deploy

如果您不喜欢部署jar,则需要更改pom中的包装类型:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.wyndhamvo.prototype.dbscripts</groupId>
  <artifactId>DB_SCRIPTS</artifactId>
  <version>2.0.0.1</version>
  <packaging>pom</packaging>


    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptor>src/assembly/descriptor.xml</descriptor>
                </configuration>
                <executions> 
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

此外,我建议您定义所用插件的版本,如下所示:

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <descriptor>src/assembly/descriptor.xml</descriptor>
                </configuration>
                <executions> 
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

答案 1 :(得分:0)

你犯了一个错误:<file/>元素不是<snapshotRepository/>的一部分,它是部署插件的配置项!你应该按如下方式部署你的zip文件:

mvn -X clean package deploy:deploy-file -Dfile=/path/to/your-artifact-1.0.zip
相关问题