JollyRoger
JollyRoger

Reputation: 847

How to deploy an HTML file along with a web application in Tomcat 8?

I have a java web application running on Tomcat 8. The application running on localhost:8080. What I want to do is, deploying an additional html file to tomcat and make it run under localhost:8080/path. How can I do this?

Upvotes: 1

Views: 1801

Answers (1)

Selaron
Selaron

Reputation: 6184

One solution is to simply deploy a trivial new web application on context path /path serving only that html file. This way you don't need to touch your existing ROOT application:

Create a apache-tomcat/webApps/path/WEB-INF/web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app 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-app_3_1.xsd"
  version="3.1"
  metadata-complete="true">

  <display-name>Additional HTML File</display-name>
  <description>
     Additional HTML File
  </description>
</web-app>

Create a apache-tomcat/webApps/path/index.html :

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <h1>Additional HTML File!!!2</h1>
</body>
</html>

Start the tomcat and visit http://localhost:8080/path

This will show you the index.html file.

Upvotes: 1

Related Questions