This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes File not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "File not found" Watch "File not found" New topic

File not found

Maalti Iyer
Ranch Hand

Joined: Jul 11, 2001
Posts: 52

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 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 is stored.
URL url = this.getClass().getClassLoader().getResource("");
But if I specify
URL url = this.getClass().getClassLoader().getResource("/com/");
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?.
Maalti Iyer
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

It looks for the exact file you specify, in that exact context. Therefore "/" matches the first file found on the ClassPath, and "/com/" matches the first file found in the "com" sub-context on the ClassPath. Otherwise "" could accidentally be matched by "/some/other/location/" by accident and you'd have a good chance of returning the wrong file without realising.
I agree. Here's the link:
subject: File not found
jQuery in Action, 3rd edition