• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Tony Ennis
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.
 
Paul Clapham
Sheriff
Posts: 22819
43
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?"
 
Henry Wong
author
Sheriff
Posts: 23295
125
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: 22819
43
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: 22819
43
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!