• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

class.getResource(.) ... why?  RSS feed

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In some web service code, I am seeing the following:




What does the getResource() thing do? It returns the directory of the SnapshotService class as a URI... But why? As far as I can tell, the URL-as-a-String is always used.
 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It searches the classpath and produces a URL which points to the actual location of the SnapshotService class. For example if the class is deployed in a jar then it's going to be a file://...jar:... kind of URL. You could do some debugging to see the actual value if you were interested.
 
Tony Ennis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did. the getResource() returned the directory the class lived in as a 'file' type URI. I suppose what I am really asking is, "Why would you want to?"
 
author
Sheriff
Posts: 23608
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case, I am not sure if it actually does anything. That constructor is for defining a relative url, from a base url. But the specified url is fully qualified -- unless there is some option that I don't know about, I am not sure if it does anything.

Henry
 
Paul Clapham
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what that constructor does either. And that's after I read the API documentation for it, which just made my eyes bleed. It might be interesting to see what URL was the result.
 
Tony Ennis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah! But I specified the web service URL on the input of the tool that generated that snippet. So perhaps if had specified
qqq.wsdl then that code would look for the wsdl in the same directory as the class. That could be useful when I'm trying
to generate the service code for the first time or from scratch.

 
Paul Clapham
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tony Ennis wrote:So perhaps if had specified qqq.wsdl then that code would look for the wsdl in the same directory as the class.



Yeah, that's probably what it would do. Or more precisely it would produce a URL referring to the WSDL under the assumption that it was in the same directory as the class.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!