简体   繁体   English

Tomcat - maven - 如何将静态页面添加到WAR文件中?

[英]Tomcat - maven - how to add the static pages to the WAR file?

When building the WAR file (for Tomcat) via Maven the static pages are not added. 通过Maven构建WAR文件(对于Tomcat)时,不会添加静态页面。 I can see that in other Eclipse projects (created with another artififact?) the web pages are automatically added to the WAR. 我可以看到在其他Eclipse项目中(使用另一个artififact创建?),网页会自动添加到WAR中。

When I add manually to the Eclipse config file 'org.eclipse.wst.common.component' the following lines then the static files are added to the war. 当我手动向Eclipse配置文件'org.eclipse.wst.common.component'添加以下行时,静态文件被添加到war中。

<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>

HOW can I have the static pages added using a Maven script (clean install? Then I am not dependent on a specific IDE settings file. 我如何使用Maven脚本添加静态页面(干净安装?然后我不依赖于特定的IDE设置文件。

[1] The src/main/webapp/WEB-INF/web.xml file is: [1] src / main / webapp / WEB-INF / web.xml文件是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns="http://java.sun.com/xml/ns/javaee" 
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
   id="WebApp_ID" version="3.0">
   <display-name>User Management</display-name>
   <servlet>
      <servlet-name>Jersey RESTful Application</servlet-name>
      <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
         <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>nl.deholtmans.Restfull01UserManagement</param-value>
         </init-param>
      </servlet>
   <servlet-mapping>
   <servlet-name>Jersey RESTful Application</servlet-name>
      <url-pattern>/rest/*</url-pattern>
   </servlet-mapping>
   <!-- NOTICE: the next lines make no difference
   <servlet-name>default</servlet-name>
      <url-pattern>/*</url-pattern>
   </servlet-mapping> -->
</web-app>

[2] The html files are in the folder 'WebContent' (under the Eclipse project). [2] html文件位于'WebContent'文件夹中(在Eclipse项目下)。 I also tried to put them under src/main/webapp 我也尝试将它们放在src / main / webapp下

[3] The pom.xml file is: [3] 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>nl.xyz</groupId>
  <artifactId>RestJerseyJquery2</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>RestJerseyJquery2 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <build>
        <finalName>RestJerseyJquery2</finalName>
        <plugins>
                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</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>

            <plugin>
                <groupId>org.glassfish.maven.plugin</groupId>
                <artifactId>maven-glassfish-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <glassfishDirectory>${local.glassfish.home}</glassfishDirectory>
                    <user>admin</user>
                    <passwordFile>${local.glassfish.passfile}</passwordFile>
                    <domain>
                        <name>domain1</name>
                        <httpPort>8080</httpPort>
                        <adminPort>4848</adminPort>
                    </domain>
                    <components>
                        <component>
                            <name>${project.artifactId}</name>
                            <artifact>target/${project.build.finalName}.war</artifact>
                        </component>
                    </components>
                    <debug>true</debug>
                    <terse>false</terse>
                    <echo>true</echo>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency> 
            <groupId>javax.json</groupId> 
            <artifactId>javax.json-api</artifactId> 
            <version>1.0</version> 
            <scope>provided</scope>
        </dependency> 
        <dependency>
            <groupId>javax</groupId> 
            <artifactId>javaee-web-api</artifactId> 
            <version>7.0</version> 
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!--  
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.40</version>
        </dependency>  -->

        <!-- <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.8.11.2</version>
        </dependency>-->

        <!-- JSON support-->
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency> 
    </dependencies>
    <properties>
        <jersey.version>2.22</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

Put all your static files inside src/main/webapp and it should work like a charm. 将所有静态文件放在src/main/webapp ,它应该像魅力一样工作。
To build your application, try running the command mvn clean install -U . 要构建应用程序,请尝试运行命令mvn clean install -U

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM