在網上,有很多有關jdk+Tomcat的配置。我看了好多篇,在這里我暫且不評論別人寫的如何。我只想寫下自己的做法。
首先,我們先到http://java.sun.com/下好JDK。到http://www.apache.org/下TOMCAT。每個人裝的版本不一樣,我的是j2sdk1.4.2_16,Tomcat 5.0
1,安裝JDK:
選好JDK安裝的路徑,安裝完成。
(我是安裝在C://)
2,配置JDK的環境變量:
我的電腦-屬性-高級-環境變量。
(有些人是在用戶變量中配置。我是在系統變量中配置。)
3,(1)新建
變量名:JAVA_HOME
變量值:C:\j2sdk1.4.2_16
確定
(2)新建
變量名:JAVA_CLASS
變量值:C:\j2sdk1.4.2_16\lib
確定
(3)找到系統變量里中的Path
選中-編輯
在變量值的%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN
前面添加C:\j2sdk1.4.2_16\bin;
注意:別少了分號。
JDK配置結束。
自己寫一個簡單的JAVA程序測試一下。
接下來配置:
1,安裝Tomcat
走默認
Ddstination Folder選擇你的安裝路徑
關鍵:走到其中一個目錄:Plase select the path of the JVM instanlled on your system:
這個目錄是選擇你安裝JDK HOME的目錄。
我們回頭看看JAVA_HOME的環境。
選擇JAVA_HOME的路徑
C:\j2sdk1.4.2_16
繼續下一步。一直走到完成。
自己運行測試一下有沒有安裝成功。
接下來手工配置,添加虛擬目錄。
1,新建一個文件夾,給新建的文件夾起個名字。比如文件夾名:test
2,在test文件夾里再新建一個文件夾。這個文件夾名字一定為:WEB-INF
3, 在WEB-INF里新建一個記事本。
把以下代碼粘貼到記事本里。
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!-- JSPC servlet mappings start -->
<!-- JSPC servlet mappings end -->
</web-app>
4,保存,保存名一定為:web.xml
5,在 Tomcat 目錄里,來到conf目錄下
C:\Tomcat 5.0\conf
找到 server.xml 文件
用記事本打開。
到代碼的最低部。
在
</Host>
的上一行添加以下代碼:<Context path="/test" docBase="C:\\test"/>
保存退出,別修改文件名。
<Context path="/映射名" docBase="本機的絕對路徑"/>
好了,在test里自己寫個JSP程序測試一下。
啟動Tomcat
在IE里運行一下
http://localhost:8080/test
查看是否成功。
Say
2008.1.8
The End