tomcat集成免安装JDK并设置为Windows服务

TOMCAT集成JDK

1.集成免安装JDK,先把...java/jdk1.8.0_60文件夹复制到tomcat解压路径的bin目录下如D:\Documents\apache-tomcat-8.0.41\bin

2.再在bin目录下的catalina.bat和setclasspath.bat的脚本前面加上如:

set "CURRENT_DIR=%cd%"
set "JAVA_HOME=%CURRENT_DIR%\jdk1.8.0_60"

说明1.先绑定当前路径 2.再定位jdk1.8.0_60的目录。
然后就可以启动tomcat啦


如果启动TOMCAT报错,从tomcat安装目录可查看log,经检查原因是8080和8443端口被占用,占用程序是之前在Windows Server 2012上安装过功能 Internet Information Services(IIS) 绑定了占用的端口并启动,

输入命令:netstat -ano,列出所有端口的情况
netstat -aon|findstr "8080",回车,记下最后一位数字,即PID,这里是443
tasklist|findstr "8080",查看是哪个进程或者程序占用了8080端口,结果是:svchost.exe

17-Mar-2017 09:14:24.678 ?? [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["http-apr-8080"]
 java.lang.Exception: Socket bind failed: [730013] ??????????????????????????  
    at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:471)
    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:810)
    at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:476)
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:960)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:568)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:871)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:580)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:603)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:310)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484)

17-Mar-2017 09:14:24.724 ?? [main] org.apache.catalina.core.StandardService.initInternal Failed to initialize connector [Connector[HTTP/1.1-8080]]
 org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-8080]]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:568)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:871)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:580)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:603)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:310)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484)
Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:962)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    ... 12 more
Caused by: java.lang.Exception: Socket bind failed: [730013] ??????????????????????????  
    at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:471)
    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:810)
    at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:476)
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:960)
    ... 13 more

17-Mar-2017 09:14:24.818 ?? [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-bio-8443"]
17-Mar-2017 09:14:25.927 ?? [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["http-bio-8443"]
 java.net.MalformedURLException: unknown protocol: d

TOMCAT设置Windows Service

1.解压完tomcat,在环境变量里新建系统变量

 CATALINA_BASE      D:\tools\apache-tomcat-8.0.14-windows-x64\apache-tomcat-8.0.14
 CATALINA_HOME     D:\tools\apache-tomcat-8.0.14-windows-x64\apache-tomcat-8.0.14
 TOMCAT_HOME       D:\tools\apache-tomcat-8.0.14-windows-x64\apache-tomcat-8.0.14

2.在PATH变量最后加上以下这段

;%CATALINA_HOME%\lib;%CATALINA_HOME%\bin;

也可以在tomcat bin目录下,建一个脚本set-variable.bat 并以管理员身份执行执行内容如下

::set tomcat system environment variable
@echo off  
cd..
set  "UPPERDIR=%cd%"
setx  CATALINA_BASE "%UPPERDIR%" /m
setx  CATALINA_HOME "%UPPERDIR%" /m
setx  TOMCAT_HOME "%UPPERDIR%" /m
setx PATH "%PATH%;%%CATALINA_HOME%%\lib;%%CATALINA_HOME%%\bin;" /m
exit

3.cmd,使用cmd命令进入tomcat安装路径的bin目录下

4.然后执行 命令:service.bat install

5.打开windows服务:输入service.msc

6.找到Apache Tomcat的服务修改它的运行级别(自动,手动 等),设置为自动,则会开机自起,如果想立马启动可以点击服务启动按钮

一键设置tomcat环境变量,生成Windows service 并启动


::set tomcat system environment variable
@echo off  
cd..
set  "UPPERDIR=%cd%"
setx  CATALINA_BASE "%UPPERDIR%" /m
setx  CATALINA_HOME "%UPPERDIR%" /m
setx  TOMCAT_HOME "%UPPERDIR%" /m
setx PATH "%PATH%;%%CATALINA_HOME%%\lib;%%CATALINA_HOME%%\bin;" /m

::  tomcat service  install
cd bin
call service.bat install
for /f "skip=3 tokens=4" %%i in ('sc query Tomcat8') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="STOPPED" (
    net start?Tomcat8
)else(

)
exit

你可能感兴趣的:(tomcat集成免安装JDK并设置为Windows服务)