4

I am using wsimport in a web service client project to generate artifact classes based on wsdl files. I am trying to reference locally the wsdl files, by using wsdlLocation attribute. The generated services will try to create an URL based on the path to the package where the service class resides and the value of the wsdlLocation attribute.

The problem is that the generated service class is using class.getResource(".") in order to get the path to the current directory (the package/directory where the service class is). If the application is packaged in a jar (as in my case) this code returns null. I have noticed that class.getResource("") would in fact return the correct path, but changing the generated code seems like an ugly solution. I was wondering if there is some way to set the classpath, so that the previous code would return the path to the package/directory where the generated service class resides (as intended)?

Thank you

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Alina
  • 121
  • 9
  • A class doesn't reside in a directory. It resides in a package. The package could be "materialized" by a directory, or by an entry of a jar file. Your code should work whether the class is in a jar or not. If you want the package name of a class, just use Service.class.getPackage().getName() – JB Nizet Dec 06 '11 at 11:22
  • sorry - I have corrected the post. As I mentioned previously, the specified code was generated by wsimport, and I didn't want to change it. Thanks anyway. – Alina Dec 06 '11 at 11:41

3 Answers3

2

The reason why you could not get a url to a directory inside your jar file is that you forgot to enable "Add directory entries" option when creating your jar file.

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

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

Do not use regular zip creators such as WinZip, 7zip or WinRar as I don't believe that have this option.

Saeid Nourian
  • 1,606
  • 15
  • 32
0

You just use forward slash "/" in place of period or dot "." . It was a bug in earlier version but is now resolved. Check the following link to know about the bug. If using forward slash doesn't help let me know. Bug

Ajay Bhojak
  • 1,161
  • 9
  • 17
0

I would suggest you to use QName and have it as your property somewhere, it gives you peace of mind as you have the option of changing your wsdl to point to any location, in case you dont want the default relative path based approach.

IMHO I dont see any reason for not changing generated code, though it causes the pain of having a change everytime you regenerate the code.

mprabhat
  • 20,107
  • 7
  • 46
  • 63