• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File not found

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I've a very basic question regarding java classpath.
Here's how my app directory structure looks like
C:\apps\java\com\bos\order\persistence and my property file order.properties is stored under com directory. All my java classes lie under persistence directory with the package structure com.bos.order.persistence.
In my java class when I execute the following stmt I do not get the url of the location where the order.properties is stored.
URL url = this.getClass().getClassLoader().getResource("order.properties");
But if I specify
URL url = this.getClass().getClassLoader().getResource("/com/order.properties");
I'm getting the value.
My classpath looks like this C:\apps\java;
My question here is, in order for java to successfully get the resources other than .class files (like .properties and .xml) do I've to specify their location in my classpath?.
Thanks
Maalti Iyer
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep.
It looks for the exact file you specify, in that exact context. Therefore "/my.properties" matches the first my.properties file found on the ClassPath, and "/com/my.properties" matches the first my.properties file found in the "com" sub-context on the ClassPath. Otherwise "my.properties" could accidentally be matched by "/some/other/location/my.properties" by accident and you'd have a good chance of returning the wrong file without realising.
 
reply
    Bookmark Topic Watch Topic
  • New Topic