Van de Graff
Van de Graff

Reputation: 5183

Deploying just HTML, CSS webpage to Tomcat

I am just getting started on developing a website. All I have at the moment is a HTML page supported by a couple of CSS stylesheets.

Can I create a WAR file from the HTML and CSS pages? How do I deploy them on to a Tomcat server?

Thanks.

Upvotes: 98

Views: 206860

Answers (7)

Sidharth K.Burnwal
Sidharth K.Burnwal

Reputation: 546

Here is how I did it.

  1. Download your latest Tomcat version and put it in your desired place.I am using 9.0.89. https://tomcat.apache.org/download-90.cgi
  2. unzip it: tar -xzvf apache-tomcat-9.0.89.tar.gz
  3. place your HTML file in a folder in webapps.
  4. now you can access it on : http://localhost:8080/{your_folder}/

Upvotes: 0

mimo
mimo

Reputation: 6837

I struggled a bit with older version of Apache Tomcat (7.0.68) running on Windows Server 2012, but this worked for me after a little bit of experimenting:

  1. Create app folder with your static files (HTML, JS, CSS, assets, etc.).
  2. Inside the folder create META-INF folder and add empty MANIFEST.MF.
  3. Optionally zip the app folder and change the extension to .war.
  4. Upload your app to Tomcat's webapps folder, either as a .war or just folder with your files.

Turned out, that META-INF with empty MANIFEST.MF file is enough for Tomcat to serve the app. No need to add WEB-INF or anything else (at least for my version of Tomcat).

Folder structure:

MyApp (folder)
|--index.html
|--app.js
|--app.css
|--assets (folder)
   |--logo.png
   |--...
|--META-INF (folder)
   |--MANIFEST.MF (empty file)

Upvotes: 0

Art Swri
Art Swri

Reputation: 2814

(Answers are pretty old, so here's what worked for me on Ubuntu 20.04 Tomcat9) As root

  cd /var/lib/tomcat9/webapps
  mkdir -p myapp
  cd myapp
  cat >>index.html
  <html><body>MY SIMPLE PAGE </body></html>
  control-D # Press CONTROL+D to exit 'cat', create the file 'index.html'
  systemctl restart tomcat9

In browser, use URL: http://127.0.0.1/myapp
(Of course, you can make page fancier, add CSS, etc., etc.)

Upvotes: 2

Greg Dougherty
Greg Dougherty

Reputation: 3471

If you want to create a .war file you can deploy to a Tomcat instance using the Manager app, create a folder, put all your files in that folder (including an index.html file) move your terminal window into that folder, and execute the following command:

zip -r <AppName>.war *

I've tested it with Tomcat 8 on the Mac, but it should work anywhere

Upvotes: 2

Frank
Frank

Reputation: 31

Here's my step in Ubuntu 16.04 and Tomcat 8.

  1. Copy folder /var/lib/tomcat8/webapps/ROOT to your folder.

    cp -r /var/lib/tomcat8/webapps/ROOT /var/lib/tomcat8/webapps/{yourfolder}

  2. Add your html, css, js, to your folder.

  3. Open "http://localhost:8080/{yourfolder}" in browser

Notes:

  1. If you using chrome web browser and did wrong folder before, then clean web browser's cache(or change another name) otherwise (sometimes) it always 404.

  2. The folder META-INF with context.xml is needed.

Upvotes: 3

Van de Graff
Van de Graff

Reputation: 5183

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!

Upvotes: 33

Gaurav Saxena
Gaurav Saxena

Reputation: 4297

There is no real need to create a war to run it from Tomcat. You can follow these steps

  1. Create a folder in webapps folder e.g. MyApp

  2. Put your html and css in that folder and name the html file, which you want to be the starting page for your application, index.html

  3. Start tomcat and point your browser to url "http://localhost:8080/MyApp". Your index.html page will pop up in the browser

Upvotes: 166

Related Questions