2009-08-21 10:34:29 killalllsd 阅读数 27

在同一个resin下的webapp目录部署多个web应用,发现他们之间是互相独立的:

虽然多个web应用都是同一套代码,但是它们互相不会干扰,因为它们的类加载器是不一样的:

例如:

resin对每个web应用加载都是用的EnvironmentClassLoader,但是不同的web应用类加载器不一样

 

cache:com.qq.jutil.jcache.adv.AdvCache@3432a325
cacheLoad:EnvironmentClassLoader$1620999494

 

cache:com.qq.jutil.jcache.adv.AdvCache@4f6c14e7
cacheLoad:EnvironmentClassLoader$1224884654

2017-12-04 11:18:35 zjsdrs 阅读数 1726
最近遇到个很奇怪的问题,要在一个tomcat下部署两个项目,只部署任意一个项目时都可以访问,两个一起部署时,第一个部署的可以访问,第二个部署的无法访问,并且tomcat启动报错:
java.lang.IllegalStateException: Web app root system property already set to different value: 'webapp.root' = [E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp4\wtpwebapps\***\] instead of [E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp4\wtpwebapps\***\] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
    at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:165)
    at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:117)
    at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:46)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4236)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4739)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

网上找了下资料是上下文的一个属性webAppRootKey的值相同冲突了,需要重新配置一个。在任意一个项目的web.xml文件中添加下面代码解决。

<context-param>
   <param-name>webAppRootKey</param-name>
   <param-value>项目名称.root</param-value>
</context-param>
报错的这个项目是拷贝另外一个项目然后需改项目名的,所以该问题可能是因为拷贝项目导致的

2010-07-21 19:53:53 zhangb310 阅读数 40
[color=red]最近有个项目需要在tomcat部署多个项目:(个人解决方案)
第一种:[/color]
在host中加:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Context path="/xfpm222" docBase="D:\running\Xfpm2" debug="0" reloadable="true">
<Resource name="jdbc/Oraclexfpm222" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="50" maxWait="-1" username="xfpm2"

password="xfpm2" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@162.8.156.40:1521:orcl"/>
</Context>
</Host>

报错1:
java.lang.IllegalStateException: Web app root system property already set to dif
ferent value: 'webapp.root' = [D:\running\Xfpm2\] instead of [C:\Program Files\T
omcat 5.5\webapps\Xfpm2\] - Choose unique values for the 'webAppRootKey' context
-param in your web.xml files!
at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(Web
Utils.java:132)
at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebC
onfigurer.java:118)
......

解决1:
是两个项目的设置重复了,导致出错,但我发现web.xml里并没有配置webAppRootKey项,然后查阅网上资料
,原来是因为如果没有web.xm 内没有设置webAppRootKey项,是为默认设置

public static void setWebAppRootSystemProperty(ServletContext servletContext) throws IllegalStateException {
String param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM);
String key = (param != null ? param : DEFAULT_WEB_APP_ROOT_KEY);
String oldValue = System .getProperty(key);
if (oldValue != null ) {
throw new IllegalStateException ("WARNING: Web app root system property already set: " + key + " = " +


oldValue + " - Choose unique webAppRootKey values in your web.xml files!" );
}
String root = servletContext.getRealPath("/" );
if (root == null ) {
throw new IllegalStateException ("Cannot set web app root system property when WAR file is not

expanded");
}
System .setProperty(key, root);
servletContext.log("Set web app root system property: " + key + " = " + root);
}

从代码看出,该方法其实就是把该web application的根目录的绝对文件路径作为属性保存在 System的属性列表中。该属性的名字,由web.xml文件中的名为"webAppRootKey"的参数值指出。

如果不在web.xml中定义 webAppRootKey参数,那么属性名就是缺省的"webapp.root".在我们的petclinic项目中已经定义了 webAppRootKey参数,其值为"petclinic.root",因此,属性的名字

就是"petclinic.root".

最后将webAppRootKey项配置好,错误解决。

以上解释懂一点,但是自己解决方法:在web.xml中加:
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>web1.root</param-value>
</context-param>
另一个项目中加:
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>web2.root</param-value>
</context-param>


报错2:

Caught exception while loading file struts-default.xml - [unknown location]
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loa
dConfigurationFiles(XmlConfigurationProvider.java:795)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loa
dDocuments(XmlConfigurationProvider.java:132)
......

解决2:可能是出现包之间的冲突,可以把冲突的包放在tomcat的common中(xerces-2.6.2.jar)

报错3:
java.lang.NullPointerException
at jimmystudio.util.table.TableParser.getPageCount(Unknown Source)
at jimmystudio.util.table.TableParser.getPage(Unknown Source)
at jimmystudio.util.table.TableUtils.init(Unknown Source)
at org.apache.jsp.util.table.table_jsp._jspService(table_jsp.java:57)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:332)

解决3:这是同一数据库,出现找不到数据(不知道是页面缓存的问题,还是数据库连接的问题)
如果数据用同一数据库可能出现报错!!
解决另外建立数据库、用户名和密码,分开连接。


[color=red]第二种:增加虚拟目录,配置多个项目(自己还未实践)[/color]

想要通过tomcat访问你的项目,第一种方法就是把你的项目复制到tomcat目录下的webapps目录里。第二种方法就是

配置要运行的项目的路径,如下:

打开tomcat目录下的conf目录找到server.xml用记事本打开,找到<Host ....></Host>标记,先看看我的tomcat的server.xml里的Host标记里的配置:

<Host name="127.0.0.1" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Context path="" docBase="D:\HtmlTools\xinjing\yangWork\homework\web" debug="0" reloadable="true" crossContext="true"></Context>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
</Host>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Context path="" docBase="D:\HtmlTools\xinjing\teacher\GWTGXT_TEST_4\web" debug="0" reloadable="true" crossContext="true"></Context>

</Host>

我的配了两个Host,每一个Host配了一个项目,就是说我的tomcat配了两个项目。(如果没有Context path...,可以自己加上去)注意:两个Host的name就不能相同,这个name就是访

问tomcat的域名,也就是说这里每个项目配置了独立的域名。我试过在同一个Host里配两个项目(就是在</Context>后加一个<Context path>),可是这样会出错,就是说同一个域名不能配

两个项目。访问时要注意:第一个是:http://127.0.0.1:8080/Homework.html,第二个是:http://localhost:8080/GWTGXTTest.html;我的tomcat的端口配置是8080;同在server.xml配置

访问端口:

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
maxThreads="500" minSpareThreads="50" maxSpareThreads="500"
enableLookups="false" acceptCount="500"
redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>

GET方式URL乱码问题解决也是在这里,其中的UTF-8 请根据你的需要自己修改,比如GBK。

tomcat的权限请看conf目录下tomcat-users.xml,在这不多说了。
2019-10-29 16:02:30 parade0393 阅读数 27

首先说明一下我不是服务端开发,但是现在我要部署一个springBoot项目。
原来的tomcat下已经有一个springBoot项目了。所以本篇不讨论怎么从0开始在tomcat部署一个springBoot项目。


我做的工作只是吧原来webapp下面的项目拷贝了一份,然后替换其中的模版就成了另外一个项目了

刚开始后来复制的项目就是跑不起来,于是百度一通都说修改一下 application.properties 文件 spring.jmx.enabled=false ,但是我的项目是 application.yml文件。于是就不知和从下手了。
经过自己摸索,发现应该按照如下方式修改
在这里插入图片描述

2018-09-18 17:18:25 chaos_le 阅读数 2769

以同个tomcat部署2个项目作为例子

第一步:Tomcat默认空间webapps,中已经存在一个项目(myProject)了,此时要增加一个项目运行可以新建一个名为webapp1(或者其他看实际情况)的文件夹,然后加入你要部署的新项目(myProject1)。

第二部:更改conf中的配置文件:server.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You 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.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <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>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8443" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8086" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the
         AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the APR/native implementation which always uses
         OpenSSL for TLS.
         Either JSSE or OpenSSL style configuration may be used. OpenSSL style
         configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                         certificateFile="conf/localhost-rsa-cert.pem"
                         certificateChainFile="conf/localhost-rsa-chain.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <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="D:\apache-tomcat-9.0.2\apache-tomcat-9.0.2\webapps\myProject" reloadable="false" />
      </Host>
    </Engine>
  </Service>
  <!-- 第二个项目 -->
  <Service name="Catalina">
  <!-- 此端口为8089,其他项目端口不能有冲突 -->
    <Connector port="8089" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8445" />
    <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="webapps1" unpackWARs="true" autoDeploy="true">
        <!-- 配置:项目名,项目路径 -->       
		<Context path="" docBase="D:\apache-tomcat-9.0.2\apache-tomcat-9.0.2\webapps1\myProject1" reloadable="false" /> 
        <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" />
      </Host>
    </Engine>
  </Service>
</Server>

再启动tomcat就可以了

需要分别启动多个webapp,

博文 来自: skykula
没有更多推荐了,返回首页