Eclipse 单击部署到远程 Tomcat [英] Eclipse on-click deploy to remote Tomcat

查看:18
本文介绍了Eclipse 单击部署到远程 Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在互联网上寻找这个,不知何故我找不到一个简单的方法来做到这一点.

我需要的非常简单,我相信你们中的许多人可能已经这样做了:- 我在 Eclipse 中开发 Java Web Apps,我的团队也是;- 我们有一个在 Ubuntu 机器上运行的 tomcat7 服务器,它作为一个集中的开发环境;- 我想点击部署按钮,将新数据发送到服务器并部署(重新加载),而不是每次导出战争并手动将其上传到服务器.

到目前为止似乎唯一的方法是使用 Eclipse 的 Maven 插件,它使用 tomcat 的管理器/HTML 界面.

问题:我就是无法让它工作.但不知何故,我找不到一个简单的步骤来解释如何做到这一点.我对 eclipse 或 Linux 不太熟悉,但是本地 tomcat 服务器的配置似乎很简单.我不明白为什么安装一个远程的这么难.

你能帮我详细解释一下怎么做吗?预先感谢您的耐心等待.

解决方案

是的,可以使用 Tomcat7 Maven Plugin.步骤如下:

1) 从 Eclipse Marketplace 等将 Maven Integration for Eclipse (m2eclipse) 安装到您的 Eclipse.

1.1) 导航到 Help -> Eclipse Marketplace 并搜索Maven Integration for Eclipse".

2) 从 Eclipse,创建一个 Maven 项目.

2.1) 导航到文件 -> 新建 -> 项目... -> Maven -> Maven 项目.

2.2) 单击下一步(保留所有字段为默认值).

2.3) 选择maven-archetype-webapp"并点击下一步.

2.4) 在 Group Id 和 Artifact Id 上输入任意值.(例如,Groupd Id 为org.myorg",Artifact Id 为myapp"),然后单击完成".(您将在项目的根目录中看到 pom.xml.)

3) 像这样编辑 pom.xml:(将下面的 yourhost 替换为您的主机名或 IP 地址.)

...<构建><插件><插件><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.1</version><配置><url>http://yourhost:8080/manager/text</url></配置></插件></插件></build></项目>

4) 将以下几行添加到您的 CATALINA_BASE/conf/tomcat-users.xml 并重新启动您的 tomcat.

...<role rolename="manager-script"/><user username="admin" password=""roles="manager-script"/></tomcat-users>

5) 在 Eclipse 中,运行 tomcat7:redeploy 目标.

5.1) 右键单击​​您的项目并导航到 Run As -> "Maven build...".

5.2) 在目标中输入 tomcat7:redeploy 并点击运行.

6) 创建上面的运行配置设置后,您可以从 Run -> Run Configurations 运行 tomcat7:redeploy 目标.

详情请参考以下文档:

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.0/tomcat7-maven-plugin/plugin-info.html

如果您使用其他用户而不是 admin 且密码为空(这是插件的默认设置),您需要创建 %USERPROFILE%.m2settings.xml 并编辑 pom.xml,如下所示:

%USERPROFILE%.m2settings.xml:

<服务器><服务器><id>tomcat7</id><用户名> tomcat<password>tomcat</password></服务器></服务器></设置>

%USERPROFILE% 是您的主文件夹.(例如 C:Usersyourusername)

pom.xml:

<预><代码><配置><server>tomcat7</server><url>http://localhost:8080/manager/text</url></配置>

添加 server 标签.

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.

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.

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.

Could you please help me out by explaining in detail how to do it? Thank you in advance for you patience.

解决方案

Yes, you can use Tomcat7 Maven Plugin. Here is the steps:

1) Install Maven Integration for Eclipse (m2eclipse) to your eclipse from Eclipse Marketplace etc.

1.1) Navigate to Help -> Eclipse Marketplace and search "Maven Integration for Eclipse".

2) From eclipse, create a maven project.

2.1) Navigate to File -> New -> Project... -> Maven -> Maven Project.

2.2) Click Next (Leave all fields with default).

2.3) Select "maven-archetype-webapp" and click Next.

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.)

3) Edit pom.xml like this: (Replace yourhost below with your hostname or ip address.)

<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.

<tomcat-users>
  ...
  <role rolename="manager-script"/>
  <user username="admin" password="" roles="manager-script"/>
</tomcat-users>

5) From eclipse, run tomcat7:redeploy goal.

5.1) Right click your project and navigate to Run As -> "Maven build...".

5.2) Enter tomcat7:redeploy to Goals and click Run.

6) Once you create the run configuration setting above, you can run tomcat7:redeploy goal from Run -> Run Configurations.

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/maven-plugin-2.1/index.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%.m2settings.xml and edit pom.xml like below:

%USERPROFILE%.m2settings.xml:

<settings>
  <servers>
    <server>
      <id>tomcat7</id>
      <username>tomcat</username>
      <password>tomcat</password>
    </server>
  </servers>
</settings>

%USERPROFILE% is your home folder. (e.g. C:Usersyourusername)

pom.xml:

<configuration>
  <server>tomcat7</server>
  <url>http://localhost:8080/manager/text</url>
</configuration>

Add server tag.

这篇关于Eclipse 单击部署到远程 Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆