Results 1 to 7 of 7

Thread: refering a file in placeholder

  1. #1
    Join Date
    Oct 2008
    Posts
    4

    Default refering a file in placeholder

    Hi all,

    I'm bulding a web app packaged in an ear archive.
    This ear is targeted to be deployed on several platforms (jetty, tomcat, jonas & weblogic).

    My web.xml refers to an applicationContext.xml file.
    In this file, I register a PropertyPlaceholderConfigurer bean.
    I want to put the property file (registered in the "locations" property of the bean above) outside the ear.
    ==> I will be able to customize my application depending on each platform settings (URLs of other servers, ....)

    My problem is how to define in a generic way the location of my property file.
    I found a solution for Application servers based on tomcat (ex : tomcat, jonas)
    ==>
    Code:
     <bean class="org.springframework....PropertyPlaceholderConfigurer">
       <property name="locations">
         <value>file:${catalina.base}/conf/myappli/myAppli.properties</value>
       </property>
    It works well. But other application servers (like jetty and weblo), the system property ${catalina.base} is not defined.

    One solution could be making conditional initialisation in spring beans ?
    For instance :
    Code:
    < < < if ${catalina.base} is defined  ==> use > > >  (Tomcat based servers)
     <bean class="org.springframework....PropertyPlaceholderConfigurer">
       <property name="locations">
         <value>file:${catalina.base}/conf/myappli/myAppli.properties</value>
       </property>
      </bean>
    < < < else if ${DOMAIN_HOME} is defined  ==> use > > > (WEBLOGIC)
     <bean class="org.springframework....PropertyPlaceholderConfigurer">
       <property name="locations">
         <value>file:${DOMAIN_HOME}/.../conf/myappli/myAppli.properties</value>
       </property>
      </bean>
    < < < end if > > >
    Thanks for your help.

    Regards
    Guillaume Lundy

  2. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    You can define the properties file as a classpath resource (use classpath: prefix) and then just make sure necessary file remains at the target server classpath.

  3. #3
    Join Date
    Oct 2008
    Posts
    4

    Default

    I thought about this but I think putting config files in the classpath of a Application server is not a good practice.

    With EARs, remaining Class path folders are lib.ext folders. IMO, lib.ext folders are not targeted to host config files

    Guillaume

  4. #4
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Why do you say that 'I think putting config files in the classpath of a Application server is not a good practice'? It's a normal practice, moreover, it allows you to use a very flexible mechanism of environment settings loading.

  5. #5
    Join Date
    Oct 2008
    Posts
    4

    Default

    Refering to
    jonas.objectweb.org/JOnAS_4_7/doc/PG_J2eeApps.html,

    Application servers classloaders hierarchies are complex and several levels are identified
    Example for jonas/tomcat but it is the same for JBOSS, Weblo, ...

    - CATALINA_HOME ( = JONAS_ROOT) are classpaths reserved for the AS binaries
    (ex : JONAS_ROOT/lib/catalina/common/lib, CATALINA_HOME/common/lib )
    A good practice is to avoid putting application files here

    - CATALINA_BASE (= JONAS_BASE) is reseved for one instance of the server. In this one, you deploy your apps in /apps, /webapps, ... and config in /conf.
    Sub folder of CATALINA_BASE added to the classpath are : CATALINA_HOME/server/lib and CATALINA_HOME/common/lib.
    Their naming convention indicates that are targeted to host jar files instead of config files.
    Unfortunatly, CATALINA_BASE/conf is not part of the classpath when you exectue run JONAS, TOMCAT....

    Guillaume LUNDY

  6. #6
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    I don't suggest to put the files to the one of ap-server specific directories. I suggest to put the files at the completely separated dedicated user-defined space and modify classpath of the AS JVM in order to include them.

  7. #7
    Join Date
    Oct 2008
    Posts
    4

    Default

    Hi, I found the solution..... which s very simple.
    I looked at the jonas.sh script and I saw that the folder $JONAS_BASE/conf was sistematically added in the classpath.
    So I add my property file in this folder and define it in spring like this:
    <bean class="org.springframework....PropertyPlaceholderC onfigurer">
    <property name="locations">
    <value>classpath:/myappli/myAppli.properties</value>
    </property>
    </bean>
    For other application servers, if a conf folder is not in the Classpath, I will add it by myself

    Regards.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •