getResource can't find file???

Discussion in 'Java' started by Todd, Jul 20, 2005.

  1. Todd

    Todd Guest

    Can someone tell me what I'm missing?

    I have a .war file with the structure:

    /WEB-INF
    |
    +-- classes
    |
    + --- package name folder
    | |
    | + -- myClass.class
    |
    + --- myProperties.properties

    When I do a myClass.getResource("myProperties.properties") it is not
    being found. I thought everything under the WEB-INF is on the
    classpath, so I can't understand why. Can someone help?

    TIA
    Todd, Jul 20, 2005
    #1
    1. Advertising

  2. On 20 Jul 2005 06:57:08 -0700, Todd wrote:

    > /WEB-INF
    > |
    > +-- classes

    ....
    > + --- myProperties.properties
    >
    > When I do a myClass.getResource("myProperties.properties")


    Try..

    myClass.getResource("/myProperties.properties")

    HTH

    --
    Andrew Thompson
    physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
    Controlling You Through A Chip In Your Butt Since 1999
    Andrew Thompson, Jul 20, 2005
    #2
    1. Advertising

  3. Todd

    Todd Guest

    Andrew,
    Worked like a charm! I owe you one.

    Thanks,
    Todd
    Todd, Jul 20, 2005
    #3
  4. Todd wrote:
    > Can someone tell me what I'm missing?
    >
    > I have a .war file with the structure:
    >
    > /WEB-INF
    > |
    > +-- classes
    > |
    > + --- package name folder
    > | |
    > | + -- myClass.class
    > |
    > + --- myProperties.properties
    >
    > When I do a myClass.getResource("myProperties.properties") it is not
    > being found. I thought everything under the WEB-INF is on the
    > classpath, so I can't understand why. Can someone help?


    Read the javadoc for java.lang.Class.getResource() carefully, especially
    the second paragraph, especially the part about the package name.

    Ray

    --
    XML is the programmer's duct tape.
    Raymond DeCampo, Jul 20, 2005
    #4
  5. Todd

    Roedy Green Guest

    On 20 Jul 2005 06:57:08 -0700, "Todd" <>
    wrote or quoted :

    >When I do a myClass.getResource("myProperties.properties") it is not
    >being found. I thought everything under the WEB-INF is on the
    >classpath, so I can't understand why. Can someone help?


    getResource is just a thing to generate you an URL to the resource.

    See http://mindprod.com/jgloss/images.html

    for the many ways to get an image.

    Once you understand that, you should be able to solve your problem.

    You have to make sure your resource is where you think it is under the
    correct membername.


    Try signing your applet. The problem may be the resource is not
    "downstream" of the web page.

    --
    Bush crime family lost/embezzled $3 trillion from Pentagon.
    Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
    http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

    Canadian Mind Products, Roedy Green.
    See http://mindprod.com/iraq.html photos of Bush's war crimes
    Roedy Green, Jul 23, 2005
    #5
  6. Roedy Green wrote:
    > On 20 Jul 2005 06:57:08 -0700, "Todd" <>
    > wrote or quoted :
    >
    >
    >>When I do a myClass.getResource("myProperties.properties") it is not
    >>being found. I thought everything under the WEB-INF is on the
    >>classpath, so I can't understand why. Can someone help?

    >
    >
    > getResource is just a thing to generate you an URL to the resource.
    >
    > See http://mindprod.com/jgloss/images.html
    >
    > for the many ways to get an image.
    >
    > Once you understand that, you should be able to solve your problem.
    >
    > You have to make sure your resource is where you think it is under the
    > correct membername.
    >
    >
    > Try signing your applet. The problem may be the resource is not
    > "downstream" of the web page.
    >


    Once again, it is not necessary to sign an applet to access resources
    that are "downstream", as you say.

    Ray

    --
    XML is the programmer's duct tape.
    Raymond DeCampo, Jul 23, 2005
    #6
    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. Manish Hatwalne

    getResource()

    Manish Hatwalne, Feb 9, 2004, in forum: Java
    Replies:
    7
    Views:
    5,980
    Andrew Thompson
    Feb 10, 2004
  2. David Favro

    ClassLoader.getResource() failure

    David Favro, Jun 19, 2004, in forum: Java
    Replies:
    1
    Views:
    25,006
    Jim Sculley
    Jun 19, 2004
  3. Replies:
    0
    Views:
    1,037
  4. Replies:
    0
    Views:
    2,922
  5. Ryan
    Replies:
    3
    Views:
    1,963
    Jean-Baptiste Nizet
    Oct 18, 2007
Loading...

Share This Page