You might want to try putting the WSDL (and XSDs) into the JAR project in a
folder called META-INF/wsdl. When you generate the artifacts using
wsdl2java, you can do something like the pattern shown with this Ant task
(yes, you could do similar with Maven)
<target name="cxfWSDLToJava" depends="init, copy-wsdl-local">
<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
* **<arg value="-wsdlLocation" />*
* <arg value="/META-INF/wsdl/${ws.endpointName}.wsdl" />*
<arg value="-d" />
<arg value="${src}" />
<arg value="-client" />
<arg value="-verbose" />
* **<arg value="${src}/META-INF/wsdl/${ws.endpointName}.wsdl" />*
<classpath>
<path refid="cxf.classpath" />
<path refid="project.classpath" />
</classpath>
</java>
</target>
This causes the generated code to look like this and it IS found in the JAR
in the classpath as you describe: (notice the generated path is
"/META-INF/wsdl/... "
/**
* This class was generated by Apache CXF 2.7.0
* 2012-10-27T16:53:04.359-04:00
* Generated source version: 2.7.0
*
*/
@WebServiceClient(name = "BookOrderManagerService",
wsdlLocation =
"/META-INF/wsdl/BookOrderManagerService.wsdl",
targetNamespace = "http://webservices.book.acme.com/")
public class BookOrderManagerService_Service extends Service {
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("
http://webservices.book.acme.com/", "BookOrderManagerService");
public final static QName BookOrderManagerServicePort = new QName("
http://webservices.book.acme.com/", "BookOrderManagerServicePort");
static {
* URL url =
BookOrderManagerService_Service.class.getResource("/META-INF/wsdl/BookOrderManagerService.wsdl");
*
if (url == null) {
java.util.logging.Logger.getLogger(BookOrderManagerService_Service.class.getName())
.log(java.util.logging.Level.INFO,
"Can not initialize the default wsdl from {0}",
"/META-INF/wsdl/BookOrderManagerService.wsdl");
}
WSDL_LOCATION = url;
}
Hope this helps.
On Thu, Nov 1, 2012 at 6:55 PM, Steve Revilak <[email protected]> wrote:
> I have a question about the static initializer that WSDL2Java places
> in service stubs.
>
> When using wsdl2java to generate code, my service classes have static
> initializers like the following:
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**~~~
> static {
> URL url = CompanyService.class.**getResource("data/wsdl/dfp-**
> CompanyService.wsdl");
> if (url == null) {
> java.util.logging.Logger.**getLogger(CompanyService.**
> class.getName())
>
> .log(java.util.logging.Level.**INFO<http://java.util.logging.Level.INFO>
> ,
> "Can not initialize the default wsdl from {0}",
> "data/wsdl/dfp-CompanyService.**wsdl");
> }
> WSDL_LOCATION = url;
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**~~~
>
> The path "data/wsdl/dfp-CompanyService.**wsdl" is the wsdl argument
> given to wsdl2java.
>
> I'm a little confused about this initializer. getResource(...) finds
> named a item in the JVM's classpath; and for me, that would be a path
> inside a jar file.
>
> I thought, "No problem -- I'll just package the wsdls in a jar, using
> the same relative paths that I gave to wsdl2java". However
>
> getResource("data/wsdl/dfp-**CompanyService.wsdl")
>
> returns a null pointer. To get a jar:file: URL from getResource(),
> you'd need a leading slash:
>
> getResource("/data/wsdl/dfp-**CompanyService.wsdl")
>
> I'd like to avoid the "Can not initialize ..." message every time my
> JVM loads a Service class. How should I be specifying the wsdl
> location to wsdl2java to avoid this?
>
> Thanks in advance.
>
> Steve
>
>
--
Mark
*
*