2016-11-28 63 views
3

通過Maven構建WAR文件(對於Tomcat)時,不會添加靜態頁面。我可以看到在其他Eclipse項目中(使用另一個工件創建的?),網頁會自動添加到WAR中。Tomcat - maven - 如何將靜態頁面添加到WAR文件?

當我手動添加到Eclipse配置文件'org.eclipse.wst.common.component'以下行時,靜態文件被添加到戰爭中。

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

我怎麼能有靜態頁面使用Maven的腳本(全新安裝?如果我不依賴於特定的IDE設置文件添加。

[1]在src /主/ web應用/ 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] HTML文件所在的文件夾 '的WebContent'(Eclipse項目下)我也試圖把他們在src /主/ web應用

[3] pom.xml f ile是:

<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> 
+0

你的靜態文件目前居住的位置是什麼? –

+0

請參見[2] ... html文件位於文件夾'WebContent'中(在Eclipse項目下)。我也試圖把它們放在src/main/webapp下。 – tjm1706

+0

它應該和你一起將靜態文件放在src/main/webapp裏面。你能再次檢查一次嗎?嘗試運行命令'mvn clean install -U' –

回答

2

把所有的靜態文件放在src/main/webapp之內,它應該像魅力一樣工作。
要構建您的應用程序,請嘗試運行命令mvn clean install -U

相關問題