Deploying Just HTML, CSS Webpage to Tomcat

Deploying just HTML, CSS webpage to Tomcat

Here's my setup: I am on Ubuntu 9.10.

Now, Here's what I did.

  1. Create a folder named "tomcat6-myapp" in /usr/share.
  2. Create a folder "myapp" under /usr/share/tomcat6-myapp.
  3. Copy the HTML file (that I need to deploy) to /usr/share/tomcat6-myapp/myapp. It must be named index.html.
  4. Go to /etc/tomcat6/Catalina/localhost.
  5. Create an xml file "myapp.xml" (i guess it must have the same name as the name of the folder in step 2) inside /etc/tomcat6/Catalina/localhost with the following contents.

    < Context path="/myapp" docBase="/usr/share/tomcat6-myapp/myapp" />
  6. This xml is called the 'Deployment Descriptor' which Tomcat reads and automatically deploys your app named "myapp".

  7. Now go to http://localhost:8080/myapp in your browser - the index.html gets picked up by tomcat and is shown.

I hope this helps!

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

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.

How to deploy html from tomcat server with Springboot

In your spring boot application you can put your index.html file in src/main/resources/static directory and it will be served by the application.

Also you may try to configure CORS in spring boot, see this answer for links.

How to deploy just HTML, CSS webpage to jetty?

With Jetty 9, the process is super simple.

In your {jetty.base}/webapps/ directory create a sub-folder that will house your static file content and put your HTML/CSS in there.

Note that the name of the directory is used to determine the contextPath of your resulting webapp. (The special case name ROOT will deploy to /)

Eg:

$ cd /opt/web/mybase
$ mkdir -p webapps/public
$ cd webapps/public
$ cp -R /home/user/Downloads/static-web-content/ .
$ ls
index.html
flower.jpg
site.css

Now you can access that content via urls like http://localhost/public/flower.jpg

Replacing a website on a Tomcat Server with a static HTML website

I found a work-around to my problem:

  1. I installed Tomcat6 on my Eclipse in Windows.
  2. I created a Dynamic Web Project.
  3. Put all my static content in the WebContent folder.
  4. Ran the server to verify everything is in order.
  5. Exported a WAR file from the project, checked "Optimize for a specific server runtime" option, runtime being "Apache Tomcat v6.0".
  6. I cleaned up the /var/lib/tomcat6/webapps/ROOT folder on the ftp linux server and reset all other settings to default.
  7. Extracted the WAR file in ROOT folder.
  8. Restarted tomcat6 using: /etc/init.d/tomcat6 restart
  9. I could successfully see my static website under "http://myIP:8080/"
  10. I wanted tomcat6 to work without this port number. The following link was very useful: http://bhou.wordpress.com/2012/03/09/how-to-install-and-configure-tomcat-6-in-ubuntu-server/
  11. My static website could be navigated to by typing in "http://myIP/"

Eclipse generated 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>StaticWebsite</display-name>
<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>

Compress JS and CSS while deployement

You can do something like that as part of the build (using YUI Compressor)

<target name="js.minify">
<apply executable="java" parallel="false">
<fileset dir="." includes="foo.js, bar.js"/>
<arg line="-jar"/>
<arg path="yuicompressor.jar"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.js" to="*-min.js"/>
<targetfile/>
</apply>
</target>

<target name="css.minify">
<apply executable="java" parallel="false">
<fileset dir="." includes="*.css"/>
<arg line="-jar"/>
<arg path="yuicompressor.jar"/>
<arg line="--line-break 0"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.css" to="*-min.css"/>
<targetfile/>
</apply>
</target>

Check out this article for more info:
http://www.julienlecomte.net/blog/2007/09/16/



Related Topics



Leave a reply



Submit