一、免配置jdk JAVA_HOME和tomcat CATALINA_HOME環境變量使用tomcat
眾說周知,使用tomcat需要有java環境,一般情況下需要配置jdk和tomcat的路徑到windows系統的環境變量中。但是也可以不用配置環境變量,直接編輯tomcat的startup.bat文件即可,下面是TOMCAT安裝路徑bin目錄下的startup.bat中的代碼,紅色字體就是配置了。其實這種方法適用於其它程序,例如:MAVEN的配置,maven運行也需要JAVA_HOME,可以在maven的bin目錄下的mvn.cmd中做類似的配置即可。
@echo off rem Licensed to the Apache Software Foundation (ASF) under one or more rem contributor license agreements. See the NOTICE file distributed with rem this work for additional information regarding copyright ownership. rem The ASF licenses this file to You under the Apache License, Version 2.0 rem (the "License"); you may not use this file except in compliance with rem the License. You may obtain a copy of the License at rem rem http://www.apache.org/licenses/LICENSE-2.0 rem rem Unless required by applicable law or agreed to in writing, software rem distributed under the License is distributed on an "AS IS" BASIS, rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. rem See the License for the specific language governing permissions and rem limitations under the License. rem --------------------------------------------------------------------------- rem Start script for the CATALINA Server rem --------------------------------------------------------------------------- setlocal rem ---------當前bat文件目錄的上級-------- set CATALINA_HOME=%~dp0.. rem -----------setclasspath.bat中要用到JAVA_HOME---------- set JAVA_HOME=E:\Program Files\Java\jdk1.8.0_131 rem Guess CATALINA_HOME if not defined set "CURRENT_DIR=%cd%" if not "%CATALINA_HOME%" == "" goto gotHome set "CATALINA_HOME=%CURRENT_DIR%" if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome cd .. set "CATALINA_HOME=%cd%" cd "%CURRENT_DIR%" :gotHome if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome echo The CATALINA_HOME environment variable is not defined correctly echo This environment variable is needed to run this program goto end :okHome set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat" rem Check that target executable exists if exist "%EXECUTABLE%" goto okExec echo Cannot find "%EXECUTABLE%" echo This file is needed to run this program goto end :okExec rem Get remaining unshifted command line arguments and save them in the set CMD_LINE_ARGS= :setArgs if ""%1""=="""" goto doneSetArgs set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1 shift goto setArgs :doneSetArgs call "%EXECUTABLE%" start %CMD_LINE_ARGS% :end pause
二、設置項目主頁路徑為http://localhost:8080、修改tomcat端口號
tomcat文件夾下的conf文件夾下有個server.xml,port后面的數字就是端口號,修改就好了(有三個),如果只是修改訪問端口(如:http://localhost:8080),只需要修改第二個就可以了。
通過添加<Context path="" docBase="E:\Program Files\apache-tomcat-8.0.37\webapps\fire360-3.0" debug="0" reloadable = "true" />這一行,來修改tomcat的主頁路徑為項目的主頁。
<?xml version='1.0' encoding='utf-8'?> <Server port="8006" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> <Context path="" docBase="E:\Program Files\apache-tomcat-8.0.37\webapps\fire360-3.0" debug="0" reloadable = "true" /> </Host> </Engine> </Service> </Server>
