Topic
7 replies Latest Post - ‏2013-08-05T11:07:07Z by NancySA
NancySA
NancySA
5 Posts
ACCEPTED ANSWER

Pinned topic Liberty Profile

‏2013-07-16T08:35:21Z |

I am trying to setup a best practices guide for setting up development environment for my java based  web app. The developer environment is set on Eclipse Juno SR2. I am able to start my application and most of the things work as expected. There is a feature in the web app where user can add their own jars to extend the capabilities. There is a classloader written to load the class which simply delegates to parent to find the class. When I invoke this module, I am hitting classnotfound exception. I checked via reflection if the classes are indeed in the JVM and they were found via reflection but via a custom loader they were not found. Even the core web app classes (which sure were found and executed and hence the webapp UIs rendered) are not visible . System classes like java.lang.String is however found. 

I am suspecting that this has something to do with liberty profile classloaders. Please note that the web app and the extension module work flawless on 8.5 WAS regular edition.

Let me know if there is something which I can try. I have tried reordering apiTypeVisbility, moving jars toglobal, common, private  libraries etc etc

 

<webApplication id="myapp" location="myapp.war" name="myapp"   contextRoot="/">
   <classloader delegation="parentFirst" apiTypeVisibility="spec,third-party, ibm-api, api" privateLibraryRef="global1">
      </classloader>
</webApplication>

 

<library id="global1"   apiTypeVisibility="spec,third-party,ibm-api,api">
      <fileset dir="C:/T/jars" includes="*"/>
       <fileset dir="C:/T/dbjars" includes="*"/>
 </library >

 

 

  • bkail
    bkail
    23 Posts
    ACCEPTED ANSWER

    Re: Liberty Profile

    ‏2013-07-17T16:36:42Z  in response to NancySA

    Can you show a snippet of how the custom class loader is created?  What class loader is it using as the parent?  When you say "core web app classes" are not found, do you mean javax.servlet, or do you mean classes within your WAR?

    • NancySA
      NancySA
      5 Posts
      ACCEPTED ANSWER

      Re: Liberty Profile

      ‏2013-07-22T13:30:18Z  in response to bkail

      Hi Bkail,

      Thanks for your response.

       Here is my Test.class where I try to invoke a custom class MyAppClass. The first method does not work, while second one works well.

                     

                      //This does not work

                     CustomFileSystemClassLoader clsLoader = new CustomFileSystemClassLoader("com.abc.xyz.MyAppClass");   
                      Object clazz =  clsLoader.loadClass("com.abc.xyz.MyAppClass").newInstance();

          
                      //This works          
                      Object clazz = Test.class.getClassLoader().loadClass("com.abc.xyz.MyAppClass").newInstance();

      Also, Here is my classloader

          public class CustomFileSystemClassLoader extends ClassLoader
                      {
                      

                         // the below method is overridden from parent and should only get invoked when the class was not found  by the parent classloader.

                   
                         public Class<?> findClass(String className) throws ClassNotFoundException
                          {
                              //load from database
                          }
                      }    
       

      If the class which I try to load is a java system class eg java.lang.String then I see that my findClass method is never invoked (as expected) but in all other cases where the class is from my web app , I see my  findClass method being invoked which is not expected as the class is available in the jvm but somehow parent could not find it.

       

      Let me know If I was able to make my self clear. Please remember that the same setup works properly in the regular WAS profile.

       

      Thanks


       

      • bkail
        bkail
        23 Posts
        ACCEPTED ANSWER

        Re: Liberty Profile

        ‏2013-07-22T14:25:42Z  in response to NancySA

        In your CustomFileSystemClassLoader constructor, are you passing a reference to your application class loader?  If not, then your class loader will only be able to load classes from the JVM.  For example, you might try something like:

        public class CustomFileSystemClassLoader extends ClassLoader {
          CustomFileSystemClassLoader() {
            super(CustomFileSystemClassLoader.class.getClassLoader());
          }
          ...
        }

        • NancySA
          NancySA
          5 Posts
          ACCEPTED ANSWER

          Re: Liberty Profile

          ‏2013-07-23T19:50:46Z  in response to bkail

          Ok, so that explains to some extent as the classloader constructure DO NOT call super. I have a little problem here as the code belongs to other software division and might be a long game to convenience them to change given that the Liberty profile is not even supported yet by the our product. I am doing this for those who are tired of the sluggish beast. Two question at this point -

          1. Why is the regular websphere appserver profile able to see app classes ?

          2. Where should be position the app jars (in liberty setup)  so that the existing code (the custom classloader) can see it ?

          Thanks for the help, we are getting closer !!

           

          • bkail
            bkail
            23 Posts
            ACCEPTED ANSWER

            Re: Liberty Profile

            ‏2013-07-23T20:52:17Z  in response to NancySA

            Based on the explanation, this shouldn't work on the full profile either.  There must be some detail that's missing, so you'll need to do a bit more investigation to figure out what's making it work there.

            Until the class loading mechanism is understood, I can't give any specific recommendation on how to place the archives to make this work on Liberty.  Are they placed in a special location on full profile?  Is some special classpath setting used on full profile?

            • NancySA
              NancySA
              5 Posts
              ACCEPTED ANSWER

              Re: Liberty Profile

              ‏2013-08-05T11:06:16Z  in response to bkail

              As far as I know, I dont think anything specific is being done in WAS full profile. I can pull up some screenshots of the WAS Full Profile settings. Anything specific you are looking at ?  Also, would it be possible to talk to you to make the troubleshooting quicker ?

              • NancySA
                NancySA
                5 Posts
                ACCEPTED ANSWER

                Re: Liberty Profile

                ‏2013-08-05T11:07:07Z  in response to NancySA

                 By the way, thanks for helping me through this, I really appreciate your time on this.