包含Web片段的WAR文件未完全部署

时间:2019-02-22 11:14:16

标签: eclipse deployment web-fragment

我想在Eclipse中导出包含WebFragment的DynamicWebProject。

我的测试项目是基于以下教程构建的:https://javajee.com/demo-deploying-using-web-fragments-web-fragmentxml-using-eclipse-feature

结构如下:

WebFragment
 |-META-INF
   |-resources
     |-images
       |- image.jpg
       |- ...
     |- index2.html  
   |- web-fragment.xml  

DynWebProject
 |-WebContent
   |-WEB-INF
     |- web.xml
 |- index.html
 |- anotherimage.jpg

在Eclipse(Kepler)的Tomcat 8服务器上运行项目时,一切正常。 如果我在index.html中引用它们,则将共享并显示WebFragment中的图像,甚至可以将index2.html设置为欢迎页面。

但是,当我尝试将项目导出为project.war并希望将其部署到我的机器上的Tomcat 8上时,web.xml和web-fragment.xml的设置似乎都没有合并,也无法引用任何内容WebFragment内的资源。

调用http://localhost:8080/project会显示没有image.jpg的index.html。 致电http://localhost:8080/project/index2.html会给我一个404错误。

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" 
    version="3.1" metadata-complete="false">
  <display-name>DynWebProject</display-name>
  <absolute-ordering>
    <name>TestFragment</name>
    <others/>
  </absolute-ordering>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>
</web-app>

web-fragment.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-fragment id="WebFragment_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd">
 <name>TestFragment</name> 
</web-fragment> 

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
        fragment<br/>
        <img alt="fragment image" src="./images/image.jpg"><br/>

        main<br/>
        <img alt="main image" src="./anotherimage.jpg">
</body>
</html>

0 个答案:

没有答案