89

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.

Van de Graff
  • 4,353
  • 13
  • 36
  • 40

4 Answers4

157

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

Gaurav Saxena
  • 4,167
  • 3
  • 17
  • 17
  • 1
    I created a folder MyApp1 under /usr/share/tomcat6/webapps/ and copied the html I am working with to MyApp1, renamed it to index.html. http://localhost:8080/MyApp1 - gives 404 error. – Van de Graff Oct 18 '10 at 10:45
  • 2
    Just downloaded tomcat 6, tried to the above on my windows XP and it worked. Since you are running it on linux (I guess from 'usr/share') I cannot recreate your scenario completely but try the following things - point your browser to localhost:8080. If you see the tomcat manager page, on the bottom left corner, click on servlet examples. Check the path of the resulting page. It points to index.html in servlets folder path of which is given by the page in browser. You need to set up your application on the same lines – Gaurav Saxena Oct 18 '10 at 12:16
  • I can confirm that gauravs method worked - i tried the same thing too. – Nidhin_toms Mar 06 '16 at 14:59
  • 1
    @VandeGraff, that could be because you do not have read permissions. Usually files put under /usr/* have permission issues.... I put mine on /home/myAccount/installations/tomcat/webapps/myApp/index.html – kholofelo Maloma Jul 14 '16 at 11:31
32

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!

cizixs
  • 9,843
  • 5
  • 43
  • 58
Van de Graff
  • 4,353
  • 13
  • 36
  • 40
3

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.

James Kraus
  • 2,927
  • 18
  • 27
Frank
  • 31
  • 1
2

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

Greg Dougherty
  • 2,853
  • 6
  • 33
  • 50