在Eclipse中配置Tomcat

为了整合eclipse和tomcat,直接在eclipse下进行tomcat开发,需要下载eclipse的tomcat插件:

下载地址:http://www.eclipsetotale.com/tomcatPlugin.html

下载后,解压。解压后的文件放到eclipse的plug目录中。

启动eclipse,点击preference。设置版本和路径。

如果启动eclipse后,没看到工具栏有如下图标,:

则说明eclipse没有识别到插件有什么办法识别呢?

办法:

从命令行启动,带上参数 -clean.

设置插件。

我装的tomcat是apache-tomcat-7.0.12,设置如下:

官网说的步骤:

Installation

    • This plugin does not contain Tomcat.
      (Download and install Tomcat before using this plugin).
      This is a design choice not to include Tomcat in the plugin distribution, this way the same plugin version can works with any Tomcat version.

    • Download tomcatPluginVxxx.zip

    • Unzip it in :
      - Eclipse_Home/dropins for Eclipse 3.4, 3.5 and 3.6
      - Eclipse_Home/plugins for Eclipse 2.1, 3.0, 3.1, 3.2 and 3.3

    • Plugin activation for Eclipse 3.x :
      - launch eclipse once using this option : -clean
      - if Tomcat icons are not shown in toolbar : select menu 'Window>Customize Perspective...>Commands', and check 'Tomcat' in 'Available command groups'

    • Set Tomcat version and Tomcat home : Workbench -> Preferences, select Tomcat and set Tomcat version and Tomcat home (Tomcat version and Tomcat home are the only required fields, other settings are there for advanced configuration).

    • This plugin launches Tomcat using the default JRE checked in Eclipe preferences window.
      To set a JDK as default JRE for Eclipse open the preference window : Window -> Preferences -> Java -> Installed JREs.
      This JRE must be a JDK (This is a Tomcat prerequisite).

    • The plugin sets itself Tomcat classpath and bootclasspath. Use Preferences -> Tomcat ->JVM Settings, only if you need specific settings.

运行java8的项目要用到apache tomcat9,但是目前eclipse不支持tomcat 9 ,可以改下tomcat9的代码

https://www.zhihu.com/question/37809905


------
我使用的eclipse当前是不支持tomcat9的,但也不是没有变通的办法来解决这个问题,以下是我在windows环境下的解决的过程(tomcat版本:apache-tomcat-9.0.0.M6),不想看过程的也可以直接跳到3直接看解决办法:
1.在bin目录下有个文件:version.bat。
在 version.bat 的末尾处(56行)有行命令 :
call "%EXECUTABLE%" version %CMD_LINE_ARGS%
在中部(38行)你能找到变量EXECUTABLE的赋值命令:
set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"
2.打开catalina.bat 搜索version 在250行左右你会发现下面一行命令:
if ""%1"" == ""version"" goto doVersion
也就是说当参数为 version时 跳转到 doVersion函数
查找doVersion (大概在306行)找到如下信息:
:doVersion
%_EXECJAVA% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
goto end
然后反编译catalina.jar找到org.apache.catalina.util.ServerInfo就会发现:如下代码:
InputStream is = ServerInfo.class.getResourceAsStream("/org/apache/catalina/util/ServerInfo.properties");
......
props.load(is);
info = props.getProperty("");
built = props.getProperty("server.built");
number = props.getProperty("server.number");
.....
if (info == null)
info = "Apache Tomcat 9.0.x-dev";
if (built == null)
built = "unknown";
if (number == null) {
number = "9.0.x";
}
serverInfo = info;
serverBuilt = built;
serverNumber = number;

3.找到lib下的catalina.jar,使用压缩软件打开。找到org/apache/catalina/util/ServerInfo.properties,然后修改与server.number的值,伪装成tomcat8即可。例如我就是直接把tomcat8.0.14的考过来的:

server.info=Apache Tomcat/8.0.14
server.number=8.0.14.0
server.built=May 11 2016 21:43:59 UTC

运行时日志:
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version: Apache Tomcat/8.0.14
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built: May 11 2016 21:43:59 UTC
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number: 8.0.14.0
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name: Windows 10
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version: 10.0
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture: amd64
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home: D:\Java\jdk1.8.0_77\jre
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version: 1.8.0_77-b03
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor: Oracle Corporation
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE: D:\Server\apache-tomcat-9.0.0.M6
五月 24, 2016 12:22:02 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME: D:\Server\apache-tomcat-9.0.0.M6

......................
原文地址:https://www.cnblogs.com/youxin/p/2867208.html