eclipse 如何将我的 Java 文件自动部署到我的 Tomcat 服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16935564/
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-09-19 20:40:57  来源:igfitidea点击:

How can I deploy my Java files to my Tomcat Server automatically?

javaeclipsetomcatservletsdeployment

提问by java java

I have a web project in Eclipse which includes a Tomcat server. The Tomcat server is installed in Path C:\Program Data ... and my Workspace from Eclipse is in D:\Webproject.

我在 Eclipse 中有一个 Web 项目,其中包括一个 Tomcat 服务器。Tomcat 服务器安装在路径 C:\Program Data ... 中,而我的 Eclipse 工作区位于 D:\Webproject 中。

Now if I have to edit my java servlet classes, I have to copy the class and JSP files from D:\Webproject to C:\Program Data\Tomcat\Webapps.... . This takes me a lot of time.

现在,如果我必须编辑我的 java servlet 类,我必须将类和 JSP 文件从 D:\Webproject 复制到 C:\Program Data\Tomcat\Webapps.... 。这需要我很多时间。

Is there any solution where the data is automatically deployed i.e. the edited classes and JSP are moved to my tomcat folder under C:.. ?

有没有自动部署数据的解决方案,即将编辑好的类和JSP移动到我的C:...下的tomcat文件夹?

回答by Olivier Masseau

Eclipse can do all that work for you.

Eclipse 可以为您完成所有工作。

To add the Tomcat server in eclipse:

在 Eclipse 中添加 Tomcat 服务器:

  • Open the 'Servers' view by going in Window->Show view->Servers.
  • Do a right click in the 'Servers' view and select New->Server.
  • Select Apache\Tomcat vX.X Server (where X.X is your Tomcat version) and click Next.
  • Enter your Tomcat installation directory and click Finish.
  • 进入“窗口”->“显示视图”->“服务器”,打开“服务器”视图。
  • 在“服务器”视图中右键单击并选择“新建”->“服务器”。
  • 选择 Apache\Tomcat vX.X Server(其中 XX 是您的 Tomcat 版本)并单击下一步。
  • 输入您的Tomcat 安装目录,然后单击完成。

To deploy your project to the server:

将项目部署到服务器:

  • In the 'Servers' view, right click on the Tomcat server and choose 'Add and Remove...' and add your project, then press Finish.
  • 在“服务器”视图中,右键单击 Tomcat 服务器并选择“添加和删除...”并添加您的项目,然后按完成。

You can then start/stop/debug/restart the server by right clicking on it.

然后,您可以通过右键单击来启动/停止/调试/重新启动服务器。

When you modify a class/jsp it should be automatically deployed.

当你修改一个类/jsp 时,它应该被自动部署。

You can also force a republish of your project by right clicking on your project name after expanding the Tomcat server entry.

您还可以通过在展开 Tomcat 服务器条目后右键单击您的项目名称来强制重新发布您的项目。

Double click on the Tomcat server entry if you need to modify the configuration of your server.

如果需要修改服务器的配置,请双击 Tomcat 服务器条目。

回答by Stefan Beike

Ant is one possibility you have. Build your war-file and copy it automaticaly to your Tomcat directory. the tomcat will compile the sources via hot deploy. Here you get a nice documentation:

蚂蚁是您拥有的一种可能性。构建您的War文件并将其自动复制到您的 Tomcat 目录。tomcat 将通过热部署编译源代码。在这里你会得到一个很好的文档:

Ant War-File

蚂蚁War档案

and the copy task:

和复制任务:

ant copy file

蚂蚁拷贝文件

回答by Himanshu Bhardwaj

You can consider configuring the Tomcat server into eclipse only, and map the corresponding webapp with that tomcat. This will give you the advantage that mostly when you edit the file it will get automatically deployed or you just have to republish the changes with a right click.

可以考虑只将Tomcat服务器配置到eclipse中,将对应的webapp映射到那个tomcat上。这会给您带来的优势是,大多数情况下,当您编辑文件时,它会自动部署,或者您只需右键单击即可重新发布更改。

For a head-start:

首先:

http://www.eclipse.org/webtools/jst/components/ws/M4/tutorials/InstallTomcat.html

http://www.eclipse.org/webtools/jst/components/ws/M4/tutorials/InstallTomcat.html

http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

回答by Konstantin Yovkov

In order to avoid copying all the stuff manually, you can create a Contextfor the Tomcat server, that points to the WEB-INFfolder of the application.

为了避免手动复制所有东西,您可以Context为 Tomcat 服务器创建一个指向WEB-INF应用程序文件夹的文件。

Go to `$TOMCAT_HOME/

转到`$TOMCAT_HOME/

Go to $TOMCAT_HOME/conf/server.xmland add a context for where is the WEB-INFof the project located. For example:

转到$TOMCAT_HOME/conf/server.xml并添加WEB-INF项目所在位置的上下文。例如:

<Context path="/Webproject" 
         docBase="D:/Webproject/WEB-INF" 
         reloadable="true" />

What does this mean ?

这是什么意思 ?

  1. The application will be accessible under http:// $tomcat-host:$tomcat-port>/Webproject.
  2. Tomcatwill search for application to run under D:/Webproject/WEB-INF.
  3. Every time you change something on some of the jspfiles or the web.xml, the application will be reloaded automatically in Tomcat. That's what the reloadable="true"stands for.
  1. 该应用程序可在 下访问http:// $tomcat-host:$tomcat-port>/Webproject
  2. Tomcat将搜索在 下运行的应用程序D:/Webproject/WEB-INF
  3. 每次更改某些jsp文件或web.xml. 这就是reloadable="true"代表的意思。

回答by Daniel Pokusa

Ant is a little bit oldschool.

Ant 有点老派。

Try Maven: http://maven.apache.org/

试试 Maven:http: //maven.apache.org/

(maven-deploy plugin)

(maven-deploy 插件)

Or gradle (imho better option): http://www.gradle.org/(gradle install task)

或 gradle(恕我直言更好的选择):http: //www.gradle.org/(gradle 安装任务)

You can also configure autodeploy in eclipse when you add your tomcat plugin to eclipse servers.

当您将 tomcat 插件添加到 eclipse 服务器时,您还可以在 eclipse 中配置 autodeploy。