---
title: "JDK和Tomcat的简单整合"
author: "supportopensource"
date: "2013-06-09T16:12:57Z"
tags: []
categories: ["编程语言"]
slug: "jdk-tomcat"
draft: false
lastmod: "2013-06-09T16:13:53Z"
id: 1884939
url: "https://supportopensource.iteye.com/blog/1884939"
---

1、新建一个web文件夹

2、拷贝一个安装后的jdk（如jdk1.7.0_21或jdk1.6.0_45）放入web文件夹，然后将jdk1.7.0_21或jdk1.6.0_45重命名为jdk，保留其中的bin、include、lib、jre四个文件夹，删除db文件夹和src.zip。

3、拷贝免安装版的tomcat，如apache-tomcat-7.0.40，放入web文件夹，然后将其重命名为tomcat。

4、在setclasspath.bat或setenv.bat中设置JAVA_HOME
（1）可以在setclasspath.bat中的设置JAVA_HOME
rem In debug mode we need a real JDK (JAVA_HOME)
if ""%1"" == ""debug"" goto needJavaHome

rem Otherwise either JRE or JDK are fine
**<span style="color:red">set JAVA_HOME=%CATALINA_HOME%\..\jdk</span>**

if not "%JRE_HOME%" == "" goto gotJreHome
if not "%JAVA_HOME%" == "" goto gotJavaHome
echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
echo At least one of these environment variable is needed to run this program
goto exit

(2)也可以在setenv.bat中设置JAVA_HOME：
rem Do not set the variables in this script(catalina_note.bat). Instead put them into a script setenv.bat in CATALINA_BASE/bin to keep your customizations separate.
**<span style="color:red">set JAVA_HOME=%CATALINA_HOME%\..\jdk</span>**

5.启动tomcat
cd web\tomcat\bin
startup.bat
或者
直接进入startup.bat，双击运行

note:如果需要编译Tomcat7源码，则需要设置系统环境变量JAVA_HOME（推荐的版本是JDK6），并将%JAVA_HOME%\bin;添加到PATH环境变量中。