Eclipse 单击部署到远程 Tomcat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17254839/
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
Eclipse on-click deploy to remote Tomcat
提问by dev.pt
I've been looking for this all-over the internet and somehow I can't find a easy way to do it.
我一直在互联网上寻找这个,不知何故我找不到一种简单的方法来做到这一点。
What I need is really simple and I believe that many of you probably do it already: - I develop Java Web Apps in Eclipse and so does my team; - we have a tomcat7 server running on a Ubuntu machine which works as a centralized Dev environment; - I would like to click a deploy button and send the new data to the server and deploy it (reload it), instead of exporting a war every time and manually upload it to server.
我需要的非常简单,我相信你们中的许多人可能已经这样做了: - 我在 Eclipse 中开发 Java Web 应用程序,我的团队也是如此;- 我们有一个在 Ubuntu 机器上运行的 tomcat7 服务器,它作为一个集中的开发环境;- 我想单击部署按钮并将新数据发送到服务器并部署(重新加载),而不是每次都导出War并手动将其上传到服务器。
Up till now seems like the only way to do it is with Maven plugin for eclipse, which uses the manager/HTML interface of tomcat.
到目前为止,似乎唯一的方法是使用 Eclipse 的 Maven 插件,它使用 tomcat 的管理器/HTML 界面。
Problem: I just can't get it to work. But somehow I can't find a simple walk through that explains how to do it. I'm not too experienced with eclipse or Linux but the configuration of local tomcat servers seems pretty straightforward. I don't understand why is so hard to install a remote one.
问题:我就是无法让它工作。但不知何故,我找不到一个简单的步骤来解释如何做到这一点。我对 eclipse 或 Linux 不太熟悉,但是本地 tomcat 服务器的配置似乎很简单。我不明白为什么安装远程的这么难。
Could you please help me out by explaining in detail how to do it? Thank you in advance for you patience.
你能帮我详细解释一下怎么做吗?预先感谢您的耐心等待。
回答by Shinichi Kai
Yes, you can use Tomcat7 Maven Plugin. Here is the steps:
是的,您可以使用 Tomcat7 Maven 插件。以下是步骤:
1) Install Maven Integration for Eclipse (m2eclipse) to your eclipse from Eclipse Marketplace etc.
1) 从 Eclipse Marketplace 等将 Maven Integration for Eclipse (m2eclipse) 安装到您的 Eclipse。
1.1) Navigate to Help -> Eclipse Marketplace and search "Maven Integration for Eclipse".
1.1) 导航到帮助 -> Eclipse Marketplace 并搜索“Maven Integration for Eclipse”。
2) From eclipse, create a maven project.
2)从eclipse,创建一个maven项目。
2.1) Navigate to File -> New -> Project... -> Maven -> Maven Project.
2.1) 导航到文件 -> 新建 -> 项目... -> Maven -> Maven 项目。
2.2) Click Next (Leave all fields with default).
2.2) 单击下一步(保留所有字段为默认值)。
2.3) Select "maven-archetype-webapp" and click Next.
2.3)选择“maven-archetype-webapp”,点击下一步。
2.4) Enter arbitrary value on Group Id and Artifact Id. (e.g. "org.myorg" for Groupd Id and "myapp" for Artifact Id) and click Finish. (You will see pom.xml in your project's root.)
2.4) 在 Group Id 和 Artifact Id 上输入任意值。(例如“org.myorg”代表Groupd Id,“myapp”代表Artifact Id)并点击Finish。(您将在项目的根目录中看到 pom.xml。)
3) Edit pom.xml like this: (Replace yourhost
below with your hostname or ip address.)
3) 像这样编辑 pom.xml: (yourhost
用你的主机名或 IP 地址替换下面的内容。)
<project ...>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>http://yourhost:8080/manager/text</url>
</configuration>
</plugin>
</plugins>
</build>
</project>
4) Add following lines to your CATALINA_BASE/conf/tomcat-users.xml and restart your tomcat.
4) 将以下行添加到您的 CATALINA_BASE/conf/tomcat-users.xml 并重新启动您的 tomcat。
<tomcat-users>
...
<role rolename="manager-script"/>
<user username="admin" password="" roles="manager-script"/>
</tomcat-users>
5) From eclipse, run tomcat7:redeploy goal.
5) 在 Eclipse 中,运行 tomcat7:redeploy 目标。
5.1) Right click your project and navigate to Run As -> "Maven build...".
5.1) 右键单击您的项目并导航到 Run As -> "Maven build..."。
5.2) Enter tomcat7:redeploy
to Goals and click Run.
5.2) 进入tomcat7:redeploy
目标并点击运行。
6) Once you create the run configuration setting above, you can run tomcat7:redeploy goal from Run -> Run Configurations.
6) 一旦你创建了上面的运行配置设置,你就可以从 Run -> Run Configurations 运行 tomcat7:redeploy 目标。
Please refer to the following documents for details:
详情请参阅以下文件:
http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Configuring_Manager_Application_Access
http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Configuring_Manager_Application_Access
http://tomcat.apache.org/maven-plugin-2.1/index.html
http://tomcat.apache.org/maven-plugin-2.1/index.html
http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/plugin-info.html
http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/plugin-info.html
If you use another user instead of admin with empty password (which is plug-in's default), you need to create %USERPROFILE%.m2\settings.xml and edit pom.xml like below:
如果您使用另一个用户而不是 admin 且密码为空(这是插件的默认设置),您需要创建 %USERPROFILE%.m2\settings.xml 并编辑 pom.xml,如下所示:
%USERPROFILE%.m2\settings.xml:
%USERPROFILE%.m2\settings.xml:
<settings>
<servers>
<server>
<id>tomcat7</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
</settings>
%USERPROFILE% is your home folder. (e.g. C:\Users\yourusername)
%USERPROFILE% 是您的主文件夹。(例如 C:\Users\您的用户名)
pom.xml:
pom.xml:
<configuration>
<server>tomcat7</server>
<url>http://localhost:8080/manager/text</url>
</configuration>
Add server
tag.
添加server
标签。