无法使用maven 3.x部署战争

时间:2011-10-08 10:25:06

标签: maven-2 maven maven-plugin maven-3 maven-release-plugin

我正在尝试使用maven 3.x将我的web应用程序部署到tomcat这里是pom.xml文件的快照

<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.demo</groupId>
    <artifactId>demoapp</artifactId>
    <version>2.2.3</version>
    <packaging>war</packaging>
    <name>Blank Webapp</name>

    <properties>
        <struts2.version>2.2.3</struts2.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-config-browser-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-junit-plugin</artifactId>
            <version>${struts2.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-mock</artifactId>
            <version>2.0.8</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>2.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>

        <plugins>
        <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
                <warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
                <url>http://localhost:8080/manager/html</url>
                <server>localhost</server>
                <path>/WebApp</path>

        </configuration>
</plugin>

        </plugins>
    </build>

</project>

我在maven mvn deploy中尝试了以下目标但是我得到了以下构建失败并出现以下错误

 Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]

在做了一些谷歌搜索后,我将以下条目添加到我的pom.xml

<distributionManagement>
    <repository>
      <id>myRepoId</id>
      <name>myCompanyReporsitory</name>
      <!-- <url>scp://nothing/</url>

      <url>${user.home}/m2/repository</url> -->
    </repository>
  </distributionManagement>

但我不确定网址应该是什么,因为使用${user.home}/m2/repository会在构建失败时出现另一个错误

Failed to deploy artifacts/metadata: No connector available to access repository myRepoId (C:\Users\admin/m2/repository) of type default using the available factories WagonRepositoryConnectorFactory -> [Help 1]

如何解决问题?

1 个答案:

答案 0 :(得分:1)

mvn deploy尝试将包目标的结果发送到POM中描述的存储库的URL。 我的目标不是在其服务器上部署Web应用程序,而是与其他人共享库。

如果你需要的是部署webapp,那么tomcat插件就是一个解决方案。

BTW:尝试部署时的连接器问题是由于要启用SCP,您需要添加wagon-scp连接器。