Topic
22 replies Latest Post - ‏2013-12-17T20:21:58Z by bwa
RChamarthy
RChamarthy
3 Posts
ACCEPTED ANSWER

Pinned topic Unable to load properties file from shared library folder.

‏2012-01-03T10:56:29Z |
I created a shared library as follows, and copied a .properties file in the shared library location.
When I tried to load the properties from my application (basically a servlet) I am running to a FileNotFoundException. Any ideas on how to load the properties from Liberty Shared library.

<library id="AppSharedLibrary">
<fileset dir="${was.server.dir}/apps/lib" includes="*.jar"/>
<fileset dir="${was.server.dir}/apps/lib" includes="*.properties"/>
</library>

Also, I tried defining the shared library as follows, which neither worked.

<library id="AppSharedLibrary">
<fileset dir="${was.server.dir}/apps/lib" includes="."/>
</library>

Thanks,
Ravi Chamarthy
  • RChamarthy
    RChamarthy
    3 Posts
    ACCEPTED ANSWER

    Re: Unable to load properties file from shared library folder.

    ‏2012-01-03T10:58:57Z  in response to RChamarthy
    Please read "star.star" as the includes in the second part of the library definition.
    For some reason, * did not appeared in the earlier post.
    • JoeChacko
      JoeChacko
      15 Posts
      ACCEPTED ANSWER

      Re: Unable to load properties file from shared library folder.

      ‏2012-01-03T11:51:02Z  in response to RChamarthy
      Surrounding text with asterisks makes it bold. If you look carefully, you will see that the . inside the double quotes is in bold.
  • JoeChacko
    JoeChacko
    15 Posts
    ACCEPTED ANSWER

    Re: Unable to load properties file from shared library folder.

    ‏2012-01-03T12:20:31Z  in response to RChamarthy
    Hi Ravi,

    Sorry you are having a problem with this. Where does this classloader definition appear in your config?

    In order for an application to see a shared library, the library must be defined or referenced from a classloader defined inside an application element.

    This means that you cannot refer to shared libraries from auto-detected apps or from apps in dropins.

    Please can you attach your entire config?
    --
    Joe Chacko
    WebSphere Application Server Liberty Profile development
    • RChamarthy
      RChamarthy
      3 Posts
      ACCEPTED ANSWER

      Re: Unable to load properties file from shared library folder.

      ‏2012-01-03T12:59:11Z  in response to JoeChacko
      Hi Joe,

      Attached the server.xml..

      Thanks,
      Ravi Chamarthy
      • JoeChacko
        JoeChacko
        15 Posts
        ACCEPTED ANSWER

        Re: Unable to load properties file from shared library folder.

        ‏2012-01-04T11:26:57Z  in response to RChamarthy
        Ravi,
        Consider your two filesets:
        <fileset dir="${was.server.dir}/apps/lib" includes="*.jar"/>
        <fileset dir="${was.server.dir}/apps/lib" includes="*.properties"/>
        The second fileset results in a list of properties files that will be added to the classpath of the classloader. The classloader only knows about archives, so in order to access your properties files as resources, you will need to put them in a JAR file, with the appropriate directory structure. If that jar is in the lib folder, it should be picked up by the first fileset anyway, so you can simply remove the second fileset.

        (Sorry, I shouldn't really have needed the context to work this out.)
        --
        Joe Chacko
        WebSphere Application Server Liberty Profile Development
        • cherelth@fr.ibm.com
          cherelth@fr.ibm.com
          2 Posts
          ACCEPTED ANSWER

          Re: Unable to load properties file from shared library folder.

          ‏2012-01-04T17:11:53Z  in response to JoeChacko
          Hi Joe,

          Thanks for the confirmation (I am working with Ravi on the WAS Liberty support).
          Just to be sure, do you also agree that this is a behavior difference with traditional WAS?
          I know that you are trying to make the WAS Liberty profile as compatible as traditional WAS as possible and for sure, in traditional WAS, you can define a shared library by just referencing a folder and property files (or any other resources for that matter) located in that folder can be loaded through the classpath mechanism.

          We are fine with the need to package our property files into a jar file for WAS Liberty (and it will also work with traditional WAS) but I just wanted to point out the different behavior between the two.
          • SystemAdmin
            SystemAdmin
            590 Posts
            ACCEPTED ANSWER

            Re: Unable to load properties file from shared library folder.

            ‏2012-01-04T18:57:16Z  in response to cherelth@fr.ibm.com
            Hi,

            For what it is worth: I can confirm what you state ("...Just to be sure, do you also agree that this is a behavior difference with traditional WAS?..."):

            The shared library behavior in the WAS base family does not require developers to put resources inside JAR files in order for the classloader to find them. My team and I use (and rely on) that feature actively for one of the projects I participate in.

            :-)

            /Nicky
          • JoeChacko
            JoeChacko
            15 Posts
            ACCEPTED ANSWER

            Re: Unable to load properties file from shared library folder.

            ‏2012-01-04T20:56:54Z  in response to cherelth@fr.ibm.com
            Hi Thomas,

            You are right. Folders on the classpath should work, but
            1) Ravi's fileset does not include any folders, only properties files.
            2) Even if it did, they aren't working in the beta - we have an open defect for this.

            • Joe Chacko, Liberty Profile Development
            • SystemAdmin
              SystemAdmin
              590 Posts
              ACCEPTED ANSWER

              Re: Unable to load properties file from shared library folder.

              ‏2012-02-27T17:44:04Z  in response to JoeChacko
              Is there a way to vote for defect we would like to be fixed first?
              In my opinion, this is a major limitation, as it prevents loading code that depends on native libraries and forces duplicating configuration files by having to create a JAR out of it.
              • agunther
                agunther
                1 Post
                ACCEPTED ANSWER

                Re: Unable to load properties file from shared library folder.

                ‏2012-03-01T23:12:57Z  in response to SystemAdmin
                Bruno,

                We actually hope to one day add a voting feature to the community. Thank you for sharing your vote for this defect. It help us prioritize. Consider your "vote" recorded.

                Thanks!
                Adam Gunther
                Manager, IBM WebSphere Application Server Liberty Profile Development
                • SystemAdmin
                  SystemAdmin
                  590 Posts
                  ACCEPTED ANSWER

                  Re: Unable to load properties file from shared library folder.

                  ‏2013-03-05T19:09:50Z  in response to agunther
                  Hi!

                  I just ran into this same issue - so please consider this another vote to fix this issue with filesets :-).

                  Thank you!
          • JoeChacko
            JoeChacko
            15 Posts
            ACCEPTED ANSWER

            Re: Unable to load properties file from shared library folder.

            ‏2012-01-04T20:56:56Z  in response to cherelth@fr.ibm.com
            Hi Thomas,

            You are right. Folders on the classpath should work, but
            1) Ravi's fileset does not include any folders, only properties files.
            2) Even if it did, they aren't working in the beta - we have an open defect for this.

            • Joe Chacko, Liberty Profile Development
            • cherelth@fr.ibm.com
              cherelth@fr.ibm.com
              2 Posts
              ACCEPTED ANSWER

              Re: Unable to load properties file from shared library folder.

              ‏2012-01-04T21:07:51Z  in response to JoeChacko
              Understood.
              Thanks for the confirmation. Good to know for us that it will eventually work.
  • RameshKarna
    RameshKarna
    1 Post
    ACCEPTED ANSWER

    Re: Unable to load properties file from shared library folder.

    ‏2013-10-31T20:49:25Z  in response to RChamarthy

    Hi,

    Is this shared library issue is resolved? please post any alternate solution if issue not solved.

    • Alasdair
      Alasdair
      55 Posts
      ACCEPTED ANSWER

      Re: Unable to load properties file from shared library folder.

      ‏2013-10-31T22:15:09Z  in response to RameshKarna

      Hi,

      If you are using 8.5.5.0 or later then this issue is resolved with the addition of new configuration syntax. From the original example of:

      <library id="AppSharedLibrary">
      <fileset dir="${was.server.dir}/apps/lib" includes="*.jar"/> 
      <fileset dir="${was.server.dir}/apps/lib" includes="*.properties"/> 
      </library>

      to get the properties picked up you would configure this:

      <library id="AppSharedLibrary">
      <fileset dir="${was.server.dir}/apps/lib" includes="*.jar"/> 
      <folder dir="${was.server.dir}/apps/lib"> 
      </library>

      The library will then load from the jar files in apps/lib and also load resources from apps/lib too.

      I hope this answers your question
      Alasdair

      • bwa
        bwa
        47 Posts
        ACCEPTED ANSWER

        Re: Unable to load properties file from shared library folder.

        ‏2013-12-16T12:55:35Z  in response to Alasdair

        Hello, does this work for an application that looks for property files on classpath ? I have applications that searches the classpath for property files, and on WAS Fullprofile we set the classpath entry on the server. But I cannot find this option on Liberty.

         

        How can I do this on Liberty ?

         

        This does not work ....:

        <library id="PropertiesLibrary">
        <folder dir="c:/some_property_folder"> 
        </library>

         

        BTW, I'm installing apps from maven, so I do not have any <application> entry in the server.xml, so there is no way of referencing the global library ...

        /bwa

         

         

        • Alasdair
          Alasdair
          55 Posts
          ACCEPTED ANSWER

          Re: Unable to load properties file from shared library folder.

          ‏2013-12-16T21:28:21Z  in response to bwa

          When you say it doesn't work how exactly doesn't it work? Is that Library associated with your application? Is the properties file in that directory, or is it in a subdirectory?

          Thanks

          Alasdair

          • bwa
            bwa
            47 Posts
            ACCEPTED ANSWER

            Re: Unable to load properties file from shared library folder.

            ‏2013-12-16T21:37:36Z  in response to Alasdair

            It doesn't work in the way that the application trying to load the propertyfile with the typical ResourceAsStream call for a  xxx.property does not find that file. In WAS Full profile we just add a classpath entry with the server, but have no found a way to do that in Liberty. The desired propertyfile to load is c:/some_property_folder/xxx.property

            It's not assosiated with the application as there is no application entry in server.xml (due to install-apps with maven, dropins folder)

             

            /bwa

          • bwa
            bwa
            47 Posts
            ACCEPTED ANSWER

            Re: Unable to load properties file from shared library folder.

            ‏2013-12-16T21:47:21Z  in response to Alasdair

            What I want to achieve is to get this resolved

             

            from the spring application context file 

            <context:property-placeholder location="classpath:xxx.properties"/>

            • Alasdair
              Alasdair
              55 Posts
              ACCEPTED ANSWER

              Re: Unable to load properties file from shared library folder.

              ‏2013-12-16T21:59:00Z  in response to bwa

              Hi,

              You need to associate the application with the shared library. You can't associate libraries with applications deployed via dropins. This gives you two choices:

              1. Deploy the application in the apps folder and add to the server.xml a webApplication or enterpriseApplication entry depending on whether you are deploying a war or ear.
              2. Put your properties in the global shared library. Any properties files in the usr/shared/lib or usr/servers/<server dir>/lib will be visible to all applications.

              The second is probably simpler, but it'll be exposed to all applications in the server which might not work too well for you.

              I hope this helps
              Alasdair

            • 5CK5
              5CK5
              6 Posts
              ACCEPTED ANSWER

              Re: Unable to load properties file from shared library folder.

              ‏2013-12-17T19:19:11Z  in response to bwa

              You might want to vote for the following feature request - http://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=42819
              This would allow having resource provider that is capable of loading properties from whatever location. Then it can be easily used in Spring as well.

              • bwa
                bwa
                47 Posts
                ACCEPTED ANSWER

                Re: Unable to load properties file from shared library folder.

                ‏2013-12-17T20:21:58Z  in response to 5CK5

                Great. Vote added ...