仅将 HTML、CSS 网页部署到 Tomcat

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3954621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:52:25  来源:igfitidea点击:

Deploying just HTML, CSS webpage to Tomcat

htmlcsstomcatweb-deployment-project

提问by Van de Graff

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

我刚刚开始开发一个网站。目前我所拥有的只是一个由几个CSS 样式表支持的 HTML 页面

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

我可以从 HTML 和 CSS 页面创建WAR 文件吗?如何将它们部署到 Tomcat 服务器上

Thanks.

谢谢。

采纳答案by Van de Graff

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

这是我的设置:我在 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/myappin your browser - the index.html gets picked up by tomcat and is shown.

  1. /usr/share 中创建一个名为“ tomcat6-myapp”的文件夹。
  2. /usr/share/tomcat6-myapp下创建一个文件夹“ myapp” 。
  3. 将 HTML 文件(我需要部署)复制到/usr/share/tomcat6-myapp/myapp。它必须命名为index.html
  4. 转到/etc/tomcat6/Catalina/localhost
  5. 使用以下内容在 /etc/tomcat6/Catalina/localhost 中创建一个 xml 文件“ myapp.xml”(我猜它必须与步骤 2 中的文件夹名称相同)。

    < Context path="/myapp" docBase="/usr/share/tomcat6-myapp/myapp" />
    
  6. 这个 xml 称为“部署描述符”,Tomcat 读取并自动部署名为“ myapp”的应用程序。

  7. 现在在浏览器中访问http://localhost:8080/myapp- index.html 被 tomcat 选中并显示出来。

I hope this helps!

我希望这有帮助!

回答by Gaurav Saxena

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

没有真正需要创建War来从 Tomcat 运行它。您可以按照以下步骤操作

  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

  1. 在 webapps 文件夹中创建一个文件夹,例如 MyApp

  2. 将您的 html 和 css 放在该文件夹中,并将您希望作为应用程序起始页面的 html 文件命名为 index.html

  3. 启动 tomcat 并将浏览器指向 url "http://localhost:8080/MyApp"。您的 index.html 页面将在浏览器中弹出

回答by Frank

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

这是我在 Ubuntu 16.04 和 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

  1. 将文件夹 /var/lib/tomcat8/webapps/ROOT 复制到您的文件夹中。

    cp -r /var/lib/tomcat8/webapps/ROOT /var/lib/tomcat8/webapps/{你的文件夹}

  2. 将您的 html、css、js 添加到您的文件夹中。

  3. 在浏览器中打开“ http://localhost:8080/{yourfolder}”

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.

  1. 如果您使用 chrome 网络浏览器并且之前做了错误的文件夹,那么清理网络浏览器的缓存(或更改另一个名称)否则(有时)它总是 404。

  2. 需要带有 context.xml 的文件夹 META-INF。

回答by Greg Dougherty

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:

如果您想创建一个 .war 文件,您可以使用 Manager 应用程序部署到 Tomcat 实例,创建一个文件夹,将您的所有文件(包括 index.html 文件)放入该文件夹中,将您的终端窗口移动到该文件夹​​中,然后执行以下命令:

zip -r <AppName>.war *

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

我已经在 Mac 上用 Tomcat 8 测试过它,但它应该可以在任何地方工作