Class.getResource (".") Returns null

I use wsimport in a web service client project to create artifact classes based on wsdl files. I am trying to link locally to wsdl files using the wsdlLocation attribute. The generated services will try to create a URL based on the package path where the service class is located and the value of the wsdlLocation attribute.

The problem is that the generated service class uses class.getResource(".") To get the path to the current directory (the directory / directory where the service class is located). If the application is packaged in a jar (as in my case), this code returns null. I noticed that class.getResource ("") will actually return the correct path, but modifying the generated code seems like an ugly solution. I was wondering if there is a way to set the classpath so that the previous code returns the path to the package / directory where the generated service class is located (as expected)?

thanks

+4
source share
3 answers

The reason you cannot get the URL in the directory inside your jar file is because you forgot to enable the "Add entries to directory" option when creating the jar file.

If you used eclipse to create the jar file, just enable the "Add entries to directory" option.

If you use the jdk jar command, I think the option is enabled by default.

Do not use ordinary zip creators such as WinZip, 7zip or WinRar, as I do not believe that you have this option.

+1
source

I suggest you use QName and use it as your property somewhere, it gives you peace of mind, since you have the option to change your wsdl to point to any place if you don't want a relative path based on the default approach.

IMHO I see no reason to change the generated code, although it causes pain every time the code is changed.

0
source

You simply use the slash β€œ/” instead of the period or period β€œ.”, This was a bug in an earlier version, but now it is resolved. Check the following link to find out about the error. If using a slash doesn't help, let me know. Bug

0
source

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


All Articles