0 Replies Latest reply on Apr 8, 2005 6:00 AM by Mikhail Maksimov

    Troubles reading package version info.

    Mikhail Maksimov Newbie

      While porting an application from WebLogic server to 4.0.0, I've noticed a strange feature of the server's classloader. Well, it was hard to miss a NullPointerException raised deep inside an EJB method call.... ;)

      In brief, the problem is this: if jar file with my.test.package classes is stored in /lib directory of the configuration, java.lang.Package.getPackage( "my.test.package" ) call returns null, but Class.forName( "my.test.package.SomeClass" ).getPackage() returns the information from the jar's manifest.mf.

      I tried moving the jar into my webapp's WEB-INF/lib, and in this case both calls returned valid results.

      I wonder if the server can be configured in a way that allows access to manifest information of /lib jarfiles via Package.getPackage() calls... I suspect there should be some tricks, since in the array returned by Package.getPackages() there are entries that apparently correspond to some of the /lib jarfiles.

      --------------------------------------

      The effect is easily reproducable in the default server configuration: I've put test.jsp (below) into server/default/jbossweb-tomcat50.sar/ROOT.war and put the jar into server/default/lib or ....ROOT.war/WEB-INF/lib.

      test.jsp:

      <html>
      <body>
      <%
       Package pack = Class.forName( "mypackage.TestClass" ).getPackage();
       if( pack ==null ) { %><h3>nulllllll</h3><%}
       else
       {
       %><h3><%= pack.getName() %></h3>
      <pre>Spec.title : <%= pack.getSpecificationTitle() %>
      Spec.vendor : <%= pack.getSpecificationVendor() %>
      pack.toString: <%= pack.toString() %>
      </pre><%
       }
      
       pack = Package.getPackage( "mypackage" );
       if( pack ==null ) { %><h3>nulllllll</h3><%}
       else
       {
       %><h3><%= pack.getName() %></h3>
      <pre>Spec.title : <%= pack.getSpecificationTitle() %>
      Spec.vendor : <%= pack.getSpecificationVendor() %>
      pack.toString: <%= pack.toString() %>
      </pre><%
       }
      %>
      </body>
      </html>