Sometimes I see this in other people's code. But when I try, it returns null.
baseUrl = org.company.UploadService.class.getResource(".");
url = new URL(baseUrl, "http://192.168.164.32:9080/mka-web/services/UploadService?wsdl");
getResource(".")
will, in some cases, return a URL pointing to the directory that class file is in.
This thread describes the behaviour as:
a URL pointing to the directory in the class path used to load the class if the class is loaded from a directory, or null when loaded from a jar.
The last part is likely why you're getting null
. Another reason could be:
It does not work with all JVMs
Line UploadService.class.getResource(".")
returns URL matches package of class UploadServiece
, i.e. something like
file://your-path/org/company
if you are running from file system
or
jar:file://yourjar-path/org/company
if you are running from jar.
Constructor of URL
that you are using returns the url in given context. For example
new URL(new URL("http://google.com"), "yahoo.com")
returns http://google.com/yahoo.com
,
but
new URL(new URL("http://google.com"), "http://yahoo.com")
returns http://yahoo.com
because the second URL is absolute.
So, I your case the code does not make any sense: it is absolutely equialent to
new URL("http://192.168.164.32:9080/mka-web/services/UploadService?wsdl")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With