Maven动态Web项目:我的战争部署在其名称中的版本。怎么改呢?

时间:2016-07-08 14:50:14

标签: maven war

出于某种原因,我的战争被部署为name-version.war

在您将此标记为重复或甚至向我投票之前,我尝试了我可以在网上找到的所有解决方案,但不起作用。到目前为止,我已经尝试过:

  • POM中的finalName标记
  • maven-war-plugin及其属性warName
  • 编辑org.eclipse.wst.common.component并将deploy-name更改为我的名字

因此,在“在服务器上运行”之后由eclipse打开的url不起作用:

应该是: http://localhost:8080/kest/dbtest.xhtml

有效的实际网址: http://localhost:8080/kest-1.0/dbtest.xhtml

这让我疯了。

我做错了什么?

这是我的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>
    <packaging>war</packaging>
    <name>kest</name>
    <build>
    <finalName>kest</finalName>
        <resources>
            <resource>
                <directory>${basedir}/src/main/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>

                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>

        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>http://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>
        <!-- Primefaces Version 6 -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>6.0</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.0.9.Final</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>

    </dependencies>
    <groupId>my.package.kest</groupId>
    <artifactId>kest</artifactId>
    <version>1.0</version>
</project>

我的Web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>kest</display-name>
  <welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
</web-app>

2 个答案:

答案 0 :(得分:1)

我可能看起来很傻,但我不知道这是否有用。 我刚刚在最终名称声明之前将组ID,工件ID和版本移到了顶部。

请尝试以下方法:

<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>
    <packaging>war</packaging>
   <groupId>my.package.kest</groupId>
    <artifactId>kest</artifactId>
    <version>1.0</version>
    <name>kest</name>
    <build>
    <finalName>kest</finalName>
        <resources>
            <resource>
                <directory>${basedir}/src/main/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>

                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>

        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>http://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>
        <!-- Primefaces Version 6 -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>6.0</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.0.9.Final</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>

    </dependencies>

</project>

如果最终名称不起作用,请使用以下内容并尝试使用与上面相同的xml。 在maven-war-plugin中,在构建中,请更改

<warName> ${artifactId} </warName>

前:

<warName> kest </warName>

替换:

        <build>
       ..........                       
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <warName>kest</warName>
            </configuration>
        </plugin>
     .............
   <build>

答案 1 :(得分:1)

我添加了-clean到eclipse.ini并清理了&amp;重建一切,现在它可以工作(即使没有或。

也许这对其他人有帮助......