Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

grails - How to deploy multiple applications in Tomcat, share jars and have different datasources?

I want to deploy three Grails web applications in a Tomcat container. I am using Grails 1.3.7 and Tomcat 7.0.23. I want to put all commons jars in a tomcat/shared/lib directory. Why? I want to have smaller war files and reduce the amount of memory required in PermGen.

I configure the next line in conf/catalina.properites

shared.loader=${catalina.base}/shared/lib,${catalina.base}/shared/lib/*.jar

For all three applications, I execute

  grails war

I copy all the *.jars under WEB-INF/lib into $CATALINA_HOME/shared/lib

Later I generate the war files without jars for every application

grails war --nojars

I put all three wars in the tomcat/webapps directory. The production dataSource in conf/DataSource.groovy looks as follows for every app.

App A)

   production {
        dataSource {
            dbCreate = "update"
            username = "userA"
            password="password"
            url = "jdbc:mysql://localhost:3306/applicationA"
            driverClassName = "org.gjt.mm.mysql.Driver"
        }
    }

App B)

   production {
        dataSource {
            dbCreate = "update"
            username = "userB"
            password="password"
            url = "jdbc:mysql://localhost:3306/applicationB"
            driverClassName = "org.gjt.mm.mysql.Driver"
        }
    }

App C)

   production {
        dataSource {
            dbCreate = "update"
            username = "userC"
            password="password"
            url = "jdbc:mysql://localhost:3306/applicationC"
            driverClassName = "org.gjt.mm.mysql.Driver"
        }
    }

When I start up Tomcat the logs look like this:

Dec 11, 2011 11:28:15 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Dec 11, 2011 11:28:15 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Dec 11, 2011 11:28:15 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Dec 11, 2011 11:28:15 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property.
Dec 11, 2011 11:28:15 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Dec 11, 2011 11:28:15 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Dec 11, 2011 11:28:15 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 652 ms
Dec 11, 2011 11:28:15 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Dec 11, 2011 11:28:15 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.23
Dec 11, 2011 11:28:16 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Dec 11, 2011 11:28:22 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /Applications/apache-tomcat-7.0.23/webapps/ApplicationB-0.1war
Dec 11, 2011 11:28:22 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Dec 11, 2011 11:28:23 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /Applications/apache-tomcat-7.0.23/webapps/ApplicationA-0.1war
Dec 11, 2011 11:28:23 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Dec 11, 2011 11:28:24 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /Applications/apache-tomcat-7.0.23/webapps/ApplicationC-0.1war
Dec 11, 2011 11:28:24 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Applications/apache-tomcat-7.0.23/webapps/docs
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Applications/apache-tomcat-7.0.23/webapps/examples
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
Dec 11, 2011 11:28:25 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Dec 11, 2011 11:28:25 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Dec 11, 2011 11:28:25 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@5f24aa56')
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Applications/apache-tomcat-7.0.23/webapps/host-manager
Dec 11, 2011 11:28:25 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Applications/apache-tomcat-7.0.23/webapps/manager
Dec 11, 2011 11:28:25 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Dec 11, 2011 11:28:26 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /Applications/apache-tomcat-7.0.23/webapps/ApplicationB-0.1war
Dec 11, 2011 11:28:26 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Dec 11, 2011 11:28:26 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /Applications/apache-tomcat-7.0.23/webapps/ApplicationA-0.1war
Dec 11, 2011 11:28:26 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Dec 11, 2011 11:28:27 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /Applications/apache-tomcat-7.0.23/webapps/ApplicationC-0.1war
Dec 11, 2011 11:28:27 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Dec 11, 2011 11:28:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Applications/apache-tomcat-7.0.23/webapps/docs
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /Applications/apache-tomcat-7.0.23/webapps/examples
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
Dec 11, 2011 11:28:28 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Dec 11, 2011 11:28:28 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Dec 11, 2011 11:28:28 PM org.apache.catalina.core.ApplicationContext log
IN

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unfortunately this doesn't work in Grails, and there are a few more issues than the datasource. We looked at fixing this for 2.0 but there are still issues, so it won't work until a 2.0.x release.

The problem is static variables in the core Grails jars. Since the classes in those jars are loaded by the shared classloader, the statics are shared throughout Tomcat. As long as the jars are in each war file they're loaded by the war-specific classloader and there's no conflict between static variables. So until this is fixed you need to deploy full wars, or at least keep the grails-*.jar files in the wars.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...