1

我正在尝试使用 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>

但我不确定 URL 应该是什么,因为 using${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]

如何解决问题?

4

1 回答 1

1

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

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

BTW: The connector issue when trying to deploy is due to the fact that to enable SCP you need to add the wagon-scp connector.

于 2011-10-08T14:00:00.760 回答