4.啟動停止tomcat服務 # cd /usr/local/tomcat6/bin # ./start.sh //啟動tomcat # ./shutdown.sh //停止tomcat 查看tomcat的進程: # ps -e | grep java 出現了java這個進程的話,說明你的tomcat差不多了。 5.讓tomcat開機運行: # cd /usr/local/tomcat6/bin/jsvc-src/native/ # vi tomcat.sh Tomcat can then be run as a daemon using the following commands. cd $CATALINA_HOME ./bin/jsvc -cp ./bin/bootstrap.jar \ -outfile ./logs/catalina.out -errfile ./logs/catalina.err \ org.apache.catalina.startup.Bootstrap The file $CATALINA_HOME/bin/jsvc/native/tomcat.sh can be used as a template for starting Tomcat automatically at boot time from /etc/init.d. The file is currently setup for running Tomcat 4.1.x, so it is necessary to edit it and change the classname from BootstrapService to Bootstrap. Note that the Commons-Daemon JAR file must be on your runtime classpath to run Tomcat in this manner. The Commons-Daemon JAR file is in the Class-Path entry of the bootstrap.jar manifest, but if you get a ClassNotFoundException or a NoClassDefFoundError for a Commons-Daemon class, add the Commons-Daemon JAR to the -cp argument when launching jsvc.
三:配置tomcat應用實列 瀏覽器輸入:http://localhost:8080/ 點擊manager:輸入剛才配置的tomcat用戶:用戶admin和密碼admin 配置虛擬目錄test,並通過 http://localhost:8080/test/來訪問 1.手動配置 在 /usr/local/tomcat6/webapps目錄下, 建立testdir目錄,把相關jsp原代碼放入該目錄。 新建test.xml,並配置context和連接池 # cd /usr/local/tomcat6/webapps/ # vi test.xml 內容如下: <Context path="/test" docBase="/usr/local/tomcat6/webapps/testdir" debug="5" reloadable="true" crossC> <Resource name="jdbc/myoracle" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@192.168.1.159:1521:db01" username="oracele_db_user" password="db_owner_password" maxActive="20" maxIdle="10" maxWait="-1"/> </Context> 其中: context path="/test"----就是http://localhost:8080/test/里的test虛擬目錄 <Resource name="jdbc/myoracle" ---- myoracle連接池名 url="jdbc:oracle:thin:@192.168.1.159:1521:db01" --192.168.1.159:1521:db01是資料庫ip:埠:SID, username="oracele_db_owner_user" password="db_owner_password" ---分別是資料庫用戶和用戶密碼 打開http://localhost:8080/,點擊manager,進入后, 在Deploy 這一欄里 Deploy directory or WAR file located on server Context Path (optional): /test XML Configuration file URL: /usr/local/tomcat6/testdir/test.xml WAR or Directory URL: 留空即可 點擊deploy按鈕。即配置了一個web應用 2.通過war文件來配置。 在WAR file to deploy這一欄里 Select WAR file to upload:通過瀏覽把war文件路徑添加上, 就可以架設應用事例了,可以參照官方文檔Sample應用實例 ---------------------------------------------------- Sample Application The example app has been packaged as a war file and can be downloaded here (Note: make sure your browser doesn't change file extension or append a new one). The easiest way to run this application is simply to move the war file to your CATALINA_HOME/webapps directory. Tomcat will automatically expand and deploy the application for you. You can view it with the following URL (assuming that you're running tomcat on port 8080 as is the default): http://localhost:8080/sample If you just want to browse the code you can unpack the war file with the jar command. jar -xvf sample.war --------------------------------------------------- ************************************** 補充: 當然可以把test.xml的內容放在 /usr/local/tomcat6/conf/server.xml中的<host>與</host>之間 然後這個應用的程序的文件夾里新建 WEB-INF/web.xml 內容如下: <resource-ref> <description>Oracle Datasource example</description> <res-ref-name>jdbc/myoracle</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> 測試jdbc代碼: <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <sql:query var="rs" dataSource="jdbc/TestDB"> select id, foo, bar from testdata </sql:query> <html> <head> <title>DB Test</title> </head> <body> <h2>Results</h2>