【问题标题】:Application not accessible with just the application name in the url on maven install仅使用 Maven 安装 url 中的应用程序名称无法访问应用程序
【发布时间】:2018-02-06 20:45:06
【问题描述】:

问题:

我正在尝试来自 git hub 位置 https://github.com/javaee-samples/javaee7-samples/tree/master/jsf/bean-validation 的示例 JSF bean 验证应用程序。 我对pom.xml 文件和settings.xml 进行了必要的自定义更改,以指向我自己的本地.m2/repository。在 Wildfly 10 上部署应用程序并通过 url 作为 http://localhost:8180/bean-validation/faces 访问它后,我无法访问欢迎页面。

但是当我将 url 重写为 http://localhost:8180/bean-validation-1.0-SNAPSHOT/faces 时,我可以访问欢迎页面。

我看到在 Server--->Deployment 文件夹中,bean-validation .war 已由 maven(通过命令行中的 mvn install 命令)部署为 bean-validation-1.0-SNAPSHOT.war

我需要在我的 pom.xml 文件中进行哪些更改才能访问 URL 中仅包含 Web 应用程序名称的页面?

我自定义的pom.xml文件如下:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
<!--     <parent>
        <groupId>org.javaee7.jsf</groupId>
        <artifactId>jsf-samples</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent> -->

    <groupId>org.javaee7.jsf</groupId>
    <artifactId>bean-validation</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.11</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
    </dependency>
<!--    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
    </dependency> -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.11</version>
    </dependency>
</dependencies>
        <build>
        <plugins>
            <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

【问题讨论】:

    标签: maven jakarta-ee pom.xml contextpath


    【解决方案1】:

    要从构建的 target 目录立即部署,您可以通过在 pom.xml 文件中添加 finalName 来修复名称:

     <build>
          <finalName>bean-validation</finalName>
          ...
     </build>
    

    但是,如果将来您有一个从本地存储库或远程存储库部署应用程序的应用程序部署流程,那么您可能必须以依赖于供应商的方式配置应用程序 Web 上下文。

    如果您在 EAR 文件中部署 Web 应用程序,那么您还可以通过添加一个

    来指定 Web 模块的上下文根
      <context-root>bean-validation</context-root>
    

    到它在 application.xml 文件中的定义。

    【讨论】:

    • 嗨史蒂夫,我还没有尝试你的答案,因为我转向了别的东西。会尽力让你保持最新状态。如果它有效,将接受作为正确答案。
    猜你喜欢
    • 2013-11-25
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多