简体   繁体   中英

Generating Web Service Java Classes in Package Different from Namespace from WSDL and XSD Files

I am developing a web service in Java technologies from an existing WSDL and XSD files. The web service is interfacing with an existing client application that has namespaces starting with "java:" eg targetNamespace="java:com.mycompany.project" I am unable to change the namespace used by the client. I am using NetBeans as my IDE and it accepts the WSDL and XSD files, auto generating via jax-ws the classes.

Because the namespace starts with "java:" the application server (I am currently using Glassfish, but others may be used) rejects the deployment of the code because custom packages cannot be under the "java." package. The error is:

Error occurred during deployment: Exception while deploying the app [MyWebService] : Prohibited package name: java.com.mycompany.projecta. Please see server.log for more details.
/NetBeansProjects/MyWebService/nbproject/build-impl.xml:288: 
The module has not been deployed.
            at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:210)
            at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:106)
            at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
            at sun.reflect.GeneratedMethodAccessor488.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
            at org.apache.tools.ant.Task.perform(Task.java:348)
            at org.apache.tools.ant.Target.execute(Target.java:390)
            at org.apache.tools.ant.Target.performTasks(Target.java:411)
            at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
            at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
            at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
            at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
            at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
            at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
            at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)

To resolve this issue I am trying to modify the WSDL and XSD files on the server side to create the auto-generated classes in a different package. I added the following to the WSDL:

<definitions... >
    ...
    <jaxws:bindings>
        <jaxws:package name="com.mycompany.projecta"/>
    </jaxws:bindings>
</definitions>

Some classes are now generated within the "com.mycompany.projecta" package, but most, are not. I have tried adding...

<xsd:schemaBindings>
    <xsd:package name="com.mycompany.projecta" />
</xsd:schemaBindings>

...elements, but they do not appear to work. They were added to the "xsd:schema > xsd:annotation" within the WSDL. I have read a lot of information online on the topic and tried other alternatives, but I have not had any success.

Can you please provide me some guidance or insight as to what I might be doing wrong so I may generate my classes in the "com.mycompany.projecta" package and move on with my project?

Thank you!

I believe I have resolved my issue. I undid everything above, and added a "package" attribute to my task in my jaxws-build.xml file (I am using ANT to build the project):

<wsimport package="com.mycompany.projecta" ... >

This generated all the classes under the "com.mycompany.projecta".

I should add that I discovered this was an option by reading this:

http://jax-ws.java.net/nonav/2.1.1/docs/wsimportant.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM