Does class.getResource ("." / * Dot * /) have any special meaning?

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");
+4
source share
2 answers

getResource(".") in some cases, returns a URL pointing to the directory in which the class file is located.

This thread describes the behavior as:

A URL pointing to a directory in the class path used to load the class if the class is loaded from the catalog, or null when loading from the jar.

Perhaps the last part is probably what you get null. Another reason could be:

It does not work with all JVMs

+2
source

UploadService.class.getResource(".") URL- UploadServiece, -

file://your-path/org/company, jar:file://yourjar-path/org/company, .

URL, , URL- .

new URL(new URL("http://google.com"), "yahoo.com") http://google.com/yahoo.com, new URL(new URL("http://google.com"), "http://yahoo.com") http://yahoo.com, URL- .

, : new URL("http://192.168.164.32:9080/mka-web/services/UploadService?wsdl")

+2

Source: https://habr.com/ru/post/1545237/


All Articles