Announcement Announcement Module
Collapse
No announcement yet.
refering a file in placeholder Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          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

          Comment


          • #6
            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.

            Comment


            • #7
              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.

              Comment

              Working...
              X