Where is the JAR currently being executed?

Discussion in 'Java' started by Mark Space, Mar 17, 2007.

  1. Mark Space

    Mark Space Guest

    Hi all, here's a basic question I haven't been able to find the answer to.

    Let's say I'm executing a JAR from the command line from a location that
    isn't in the CLASSPATH. The JAR implements it's own classLoaders and
    wants to use data in the JAR to construct some classes. How does the
    classLoader (or I guess any other method) locate the JAR file being
    executed so it can load some resources?

    OK, same question, but this time my JAR file is contained inside another
    JAR file. Now how do I find it?
     
    Mark Space, Mar 17, 2007
    #1
    1. Advertising

  2. Mark Space wrote on 17.03.2007 16:44:
    > Hi all, here's a basic question I haven't been able to find the answer to.
    >
    > Let's say I'm executing a JAR from the command line from a location that
    > isn't in the CLASSPATH. The JAR implements it's own classLoaders and
    > wants to use data in the JAR to construct some classes. How does the
    > classLoader (or I guess any other method) locate the JAR file being
    > executed so it can load some resources?


    getClass().getResourceAsStream()

    Thomas
     
    Thomas Kellerer, Mar 17, 2007
    #2
    1. Advertising

  3. Mark Space

    Mark Space Guest

    Thomas Kellerer wrote:
    >
    >
    > Mark Space wrote on 17.03.2007 16:44:
    >>
    >> Let's say I'm executing a JAR from the command line from a location
    >> that isn't in the CLASSPATH. The JAR implements it's own classLoaders
    >> and wants to use data in the JAR to construct some classes. How does
    >> the classLoader (or I guess any other method) locate the JAR file
    >> being executed so it can load some resources?

    >
    > getClass().getResourceAsStream()


    I was probably unclear with that last bit. I mean resources
    generically, not specificaly a Java Resource.

    Let's say I want to muck with the class search order, loading classes
    from my package space first from the current JAR. Then defaulting to
    the parent classLoader only if the class isn't found locally.

    Hmm, is a class a resource? I haven't actually tested this yet.

    Can I getResourceX("/classes/MyPackage/subpackage/MyClass.class"); ?
     
    Mark Space, Mar 17, 2007
    #3
  4. Mark Space wrote on 17.03.2007 17:42:
    > Thomas Kellerer wrote:
    >>
    >>
    >> Mark Space wrote on 17.03.2007 16:44:
    >>>
    >>> Let's say I'm executing a JAR from the command line from a location
    >>> that isn't in the CLASSPATH. The JAR implements it's own
    >>> classLoaders and wants to use data in the JAR to construct some
    >>> classes. How does the classLoader (or I guess any other method)
    >>> locate the JAR file being executed so it can load some resources?

    >>
    >> getClass().getResourceAsStream()

    >
    > I was probably unclear with that last bit. I mean resources
    > generically, not specificaly a Java Resource.


    What do you mean with "Java Resource"?

    Any file in the .jar can be loaded using the stream returned by
    getResourceAsStream().
     
    Thomas Kellerer, Mar 17, 2007
    #4
  5. Mark Space wrote:
    > Thomas Kellerer wrote:
    >>
    >>
    >> Mark Space wrote on 17.03.2007 16:44:
    >>>
    >>> Let's say I'm executing a JAR from the command line from a location
    >>> that isn't in the CLASSPATH. The JAR implements it's own
    >>> classLoaders and wants to use data in the JAR to construct some
    >>> classes. How does the classLoader (or I guess any other method)
    >>> locate the JAR file being executed so it can load some resources?

    >>
    >> getClass().getResourceAsStream()

    >
    > I was probably unclear with that last bit. I mean resources
    > generically, not specificaly a Java Resource.
    >
    > Let's say I want to muck with the class search order, loading classes
    > from my package space first from the current JAR. Then defaulting to
    > the parent classLoader only if the class isn't found locally.
    >
    > Hmm, is a class a resource? I haven't actually tested this yet.
    >
    > Can I getResourceX("/classes/MyPackage/subpackage/MyClass.class"); ?


    Why don't you test it to find out? You could answer your own question.

    I believe the answer is yes, although this is a spur-of-the-moment,
    untested answer, whose validity should not be trusted.
     
    Joshua Cranmer, Mar 17, 2007
    #5
  6. Mark Space

    Guest

    On 3ÔÂ17ÈÕ, ÏÂÎç11ʱ44·Ö, Mark Space <marksp...@sbc..global.net> wrote:
    > Hi all, here's a basic question I haven't been able to find the answer to.
    >
    > Let's say I'm executing a JAR from the command line from a location that
    > isn't in the CLASSPATH. The JAR implements it's own classLoaders and
    > wants to use data in the JAR to construct some classes. How does the
    > classLoader (or I guess any other method) locate the JAR file being
    > executed so it can load some resources?
    >
    > OK, same question, but this time my JAR file is contained inside another
    > JAR file. Now how do I find it?


    More see here!
    http://www.flash50.com/index.php
     
    , Mar 18, 2007
    #6
  7. On Mar 18, 7:26 pm, "" <> wrote:
    ...
    > More see here!


    Oh, more stupid messages. I could pass the
    first one off as you being an imbecile, but
    this is becoming more like a concerted
    spamming effort.

    Andrew T.
     
    Andrew Thompson, Mar 18, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    611
    Arnold Peters
    Jan 5, 2005
  2. muttley
    Replies:
    0
    Views:
    2,767
    muttley
    Oct 20, 2005
  3. cyberco
    Replies:
    4
    Views:
    3,843
    Roedy Green
    Feb 14, 2006
  4. markspace
    Replies:
    2
    Views:
    491
    markspace
    Oct 7, 2011
  5. Arne Vajhøj
    Replies:
    0
    Views:
    742
    Arne Vajhøj
    Nov 6, 2011
Loading...

Share This Page