zoukankan      html  css  js  c++  java
  • 免配置环境变量使用Tomcat+设置项目主页路径为http://localhost:8080+修改tomcat端口号

    一、免配置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 FilesJavajdk1.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%incatalina.bat" goto okHome
    cd ..
    set "CATALINA_HOME=%cd%"
    cd "%CURRENT_DIR%"
    :gotHome
    if exist "%CATALINA_HOME%incatalina.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%incatalina.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 Filesapache-tomcat-8.0.37webappsfire360-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 &quot;%r&quot; %s %b" />
                   
            <Context path="" docBase="E:Program Filesapache-tomcat-8.0.37webappsfire360-3.0" debug="0" reloadable = "true" />
            
          </Host>
        </Engine>
      </Service>
    </Server>

      

  • 相关阅读:
    小tips:JS之for in、Object.keys()和Object.getOwnPropertyNames()的区别
    Promise原理讲解 && 实现一个Promise对象 (遵循Promise/A+规范)
    【笔记】原生JS实现的DOM操作
    HTML5利用canvas,把多张图合并成一张图片
    大数据之Zookeeper:zookeeper数据结构、zookeeper安装、zookeeper内部原理、分布式zookeeper部署、命令行、zookeeper的API、监听服务器动态上下线案例
    大数据Zookeeper系列之Zookeeper分布式协调服务部署
    HBase安装和基础编程
    【Hadoop入门学习系列之六】HBase基本架构、编程模型和应用案例
    【Hadoop入门学习系列之五】MapReduce 2.0编程实战
    【Hadoop入门学习系列之四】MapReduce 2.0应用场景和原理、基本架构和编程模型
  • 原文地址:https://www.cnblogs.com/hyyq/p/6938042.html
Copyright © 2011-2022 走看看