• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Resource Loading via class.getResource, class.getClassLoader().getResource and application().resourceManager()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Resource Loading via class.getResource, class.getClassLoader().getResource and application().resourceManager()


  • Subject: Resource Loading via class.getResource, class.getClassLoader().getResource and application().resourceManager()
  • From: Larry Mills-Gahl <email@hidden>
  • Date: Sat, 06 Nov 2010 14:38:29 -0400

Hello,

I'm having some difficulty with loading some resources from the source
file. I'm trying to package up transform files in the jars so they can
be accessible to any java process that loads the jar and not just
webobjects applications.
The specific task here is loading transforms and image resources from
threads spawned by a WO front end. I would rather not duplicate the
transform files in the Resources directory so that the WO process can
load them.


AccessDistributionXMLDocument contains the following fields:


    public static  String PDF_TRANSFORM_FILENAME =
"AccessTypeDistribution_XML2FOP_Portrait.xsl";
    public static  String PDF_TRANSFORM_FILE =
"com/vascalert/xml/xslt/AccessTypeDistribution_XML2FOP_Portrait.xsl";
    public static String PDF_TRANSFORM_FILE_ABSOLUTE =
"/com/vascalert/xml/xslt/AccessTypeDistribution_XML2FOP_Portrait.xsl";


And there actually is a transform in the com.vascalert.xml.xslt package



Just to exercise this in the Application constructor, I have:

logger.debug("loading resource named \""+
AccessDistributionXMLDocument.PDF_TRANSFORM_FILENAME + "\"");
logger.debug(resourceManager().pathURLForResourceNamed(AccessDistributionXMLDocument.PDF_TRANSFORM_FILENAME,
"VAJava_EOFramework", null));


logger.debug("looking for " +
AccessDistributionXMLDocument.PDF_TRANSFORM_FILE);
logger.debug("class: " +
Application.class.getResource(AccessDistributionXMLDocument.PDF_TRANSFORM_FILE));
logger.debug("classLoader: " +
Application.class.getClassLoader().getResource(AccessDistributionXMLDocument.PDF_TRANSFORM_FILE));

logger.debug("looking for  " +
AccessDistributionXMLDocument.PDF_TRANSFORM_FILE_ABSOLUTE);
logger.debug("class: " +
Application.class.getResource(AccessDistributionXMLDocument.PDF_TRANSFORM_FILE_ABSOLUTE));
logger.debug("classLoader: " +
Application.class.getClassLoader().getResource(AccessDistributionXMLDocument.PDF_TRANSFORM_FILE_ABSOLUTE));


which yields:

DEBUG Application  - loading resource named
"AccessTypeDistribution_XML2FOP_Portrait.xsl"
DEBUG Application  -
file:/Users/lmg42/Development/Eclipse.Workspaces/VascAlert_201009/Web6/VAJava_EOFramework/Resources/AccessTypeDistribution_XML2FOP_Portrait.xsl
DEBUG Application  - looking for
com/vascalert/xml/xslt/AccessTypeDistribution_XML2FOP_Portrait.xsl
DEBUG Application  - class: null
DEBUG Application  - classLoader: null
DEBUG Application  - looking for
/com/vascalert/xml/xslt/AccessTypeDistribution_XML2FOP_Portrait.xsl
DEBUG Application  - class: null
DEBUG Application  - classLoader: null



A simple exercise in resource loading from within the Wonder project
(just a class with a main method run as a Java Application from within
Eclipse):


    public static void main(String[] args) {

        System.out.println("looking for " +
AccessDistributionXMLDocument.PDF_TRANSFORM_FILE);
        System.out.println("class: " +
ResourceTest.class.getResource(AccessDistributionXMLDocument.PDF_TRANSFORM_FILE));
        System.out.println("classLoader: " +
ResourceTest.class.getClassLoader().getResource(AccessDistributionXMLDocument.PDF_TRANSFORM_FILE));

        System.out.println("looking for  " +
AccessDistributionXMLDocument.PDF_TRANSFORM_FILE_ABSOLUTE);
        System.out.println("class: " +
ResourceTest.class.getResource(AccessDistributionXMLDocument.PDF_TRANSFORM_FILE_ABSOLUTE));
        System.out.println("classLoader: " +
ResourceTest.class.getClassLoader().getResource(AccessDistributionXMLDocument.PDF_TRANSFORM_FILE_ABSOLUTE));


    }

yields:

looking for
com/vascalert/xml/xslt/AccessTypeDistribution_XML2FOP_Portrait.xsl
class: null
classLoader:
file:/Users/lmg42/Development/Eclipse.Workspaces/VascAlert_201009/Web6/VAJava_EOFramework/bin/com/vascalert/xml/xslt/AccessTypeDistribution_XML2FOP_Portrait.xsl
looking for
/com/vascalert/xml/xslt/AccessTypeDistribution_XML2FOP_Portrait.xsl
class:
file:/Users/lmg42/Development/Eclipse.Workspaces/VascAlert_201009/Web6/VAJava_EOFramework/bin/com/vascalert/xml/xslt/AccessTypeDistribution_XML2FOP_Portrait.xsl
classLoader: null



...which is what I would expect from java even though the resources is
in another framework (that is in the build path).

So, what I am trying to do is to get my report document
(AccessDistributionXMLDocument) to be able to reliably load a resource
from the classpath by name whether the report document class is called
from a webobjects application or a java utility.

I feel like I'm making this more difficult on myself than it needs to
be. Can anybody point me in the right direction for this?

Thanks

Larry



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Greetings!
  • Next by Date: Re: EOModel needs an easy tweak
  • Previous by thread: Re: EOModel needs an easy tweak
  • Next by thread: Any one try making a db4o adapter for EO?
  • Index(es):
    • Date
    • Thread