Trying to run JAX-WS Sample Application in the Metro Environment

I recently downloaded the Metro 2.0 from https://metro.java.net/.

I wanted to install it on my Tomcat 6 (apache-tomcat-6.0.18) with JDK (1.6.0_10)

I followed Java example in the "Getting started with Metro" guide from https://metro.java.net/getting-started/basic.html

Below are the issues I ran into during this process so thought of posting this for others benefit.


Issue #1 : Tomcat endorsed directory location in Ant build.xml

When you run the "server" target in build.xml it throws following error message.

C:\wsit-jaxws-fromjava>ant -Duse.tomcat=true server
Buildfile: build.xml

BUILD FAILED
C:\wsit-jaxws-fromjava\build.xml:129: C:\Tools\apache-tomcat-6.0.18\common\endorsed not found.

Total time: 0 seconds


This issue is due the wrong directory path for lib.endorsed in build.xml to fix this issue open the wsit-jaxws-fromjava\build.xml file and search for following





Change the directory value ${catalina.home}/common/endorsed to ${catalina.home}/endorsed as shown below and save the build.xml file.





Now run the "ant -Duse.tomcat=true server" command again, build should be successful.

Issue #2 : The xendorsed option is required for JDK6

Once the you are done generating the server side for this web service you need to generate the client sources for the same sample service.
When I run the "ant -Duse.tomcat=true client" command I get following error message and build is failed again.

C:\wsit-jaxws-fromjava>ant -Duse.tomcat=true client
Buildfile: build.xml
Trying to override old definition of task apt

setup:

generate-client:

BUILD FAILED
C:\wsit-jaxws-fromjava\build.xml:192: You are running on JDK6 which comes with JAX-WS 2.1 API, but this tool requires JAX-WS 2.2 API. Use the endorsed standards override mechanism (http://java.sun.com/javase/6/docs/technotes/guides/standards/), or set xendorsed="true" on .

Total time: 0 seconds


As the message says it clearly, this problem is due to the JDK6 being shipped with older version of JAX-WS API. To make the tag use a override on this you need to add one more attribute xendorsed="true" in the tag in Ant build.xml file.

Open the build.xml file and look for below tag








Now change this to add a new attribute as shown below.







Now run the "ant -Duse.tomcat=true client" command again, and this time it should generate all your client sources properly.

Issue #3 : Using the endorsed directory in JDK6

When I run the client using command "ant -Duse.tomcat=true run", it gives me below error.

C:\wsit-jaxws-fromjava>ant run
Buildfile: build.xml
Trying to override old definition of task apt

run:
[java] Exception in thread "main" java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String;
[java]     at com.sun.xml.ws.model.RuntimeModeler.processExceptions(RuntimeModeler.java:1162)
[java]     at com.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:898)
[java]     at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:666)
[java]     at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:420)
[java]     at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:254)
[java]     at com.sun.xml.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:661)
[java]     at com.sun.xml.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:649)
[java]     at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:343)
[java]     at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:326)
[java]     at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:308)
[java]     at javax.xml.ws.Service.getPort(Service.java:92)
[java]     at fromjava.client.AddNumbersImplService.getAddNumbersImplPort(AddNumbersImplService.java:72)
[java]     at fromjava.client.AddNumbersClient.main(Unknown Source)
[java] Java Result: 1

BUILD SUCCESSFUL
Total time: 2 seconds

-----------

The error message is due to client using older version of jaxws-ri which already bundled with the JDK6.
The annotation javax.xml.ws.WebFault in the rt.jar that ships with JDK1.6.0_X does not contain a messageName property
where as the javax.xml.ws.WebFault annotation that comes in the webservices-api.jar does contain this property.

To avoid this error you need to copy the \endorsed\webservices-api.jar file to /jre/lib/endorsed directory

if /jre/lib/endorsed directory does not exist in your system create it and copy the webservices-api.jar file here.

For more details on endorsed directory read details at http://java.sun.com/javase/6/docs/technotes/guides/standards/

Now run the command "ant run" you should see the successful output.

C:\Downloads\wsit-jaxws-fromjava\wsit-jaxws-fromjava>ant run
Buildfile: build.xml
Trying to override old definition of task apt

run:
[java] Invoking addNumbers(10, 20)
[java] The result of adding 10 and 20 is 30.
[java]
[java] Invoking addNumbers(-10, 20)
[java] Caught AddNumbersException_Exception: Numbers: -10, 20

BUILD SUCCESSFUL
Total time: 1 second


Let me know if you face any other issue while following steps.

Post a Comment Default Comments

  1. Metro 2.0 ha still this problems... why they do not fix these things ?

    ReplyDelete
  2. I think their emphasis is to use Metro with Glassfish 3.0. That could be one reason they didnt spend time on this sample app for tomcat. BTW Metro 2.0 core functionalities are good and I didnt see any issues using it in my recent applications.

    The build scripts used in sample app are handy and can be copied to use in our own project for server and client code generation. Let me know if you need any help on that front.

    ReplyDelete
  3. seems so frustrating to endure all the error messages. could there be a simpler way?

    ReplyDelete
  4. Hi just something I noticed on your blog. It doesn't seem to display the year of post, which is somewhat useful for older entries ;)

    ReplyDelete
  5. I was having the same problems described here also using Tomcat and this article just made my day everything is up and running now!

    Thanks a lot keep up the good work!!!

    ReplyDelete
  6. @twig - As per your feedback I was able to incorporate the year in my post headers. Hope this helps.

    ReplyDelete
  7. Great page, contained everything I needed to get the samples working. Thanks for putting it together

    ReplyDelete
  8. I tried the above steps but still same error :(
    from where you download webservices-api.jar file??

    ReplyDelete
  9. I also, would like to know where I can download the webservices-api.jar file?

    ReplyDelete
  10. The metro distribution should contain a webservices-api.jar file in lib directory. Let me know what problem you are facing? Which version of Metro are you using?

    ReplyDelete
  11. I got the same issue. java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String

    I'm using netbeans 6.9.1, java 1.6.16 tomcat 6.x, metro 2.0, try copying "endorsed" folder with webservices-api.jar to you javahome\1.6.16\jre\lib\endorsed and restart netbeans. If it didn't fix, place the same endorsed folder in \endorsed or \endorsed where catalina-home is apache tomcat6.x home and catalina-base is tomcat instance. It should fix.

    ReplyDelete
  12. I mean,

    If it didn't fix, place the same endorsed folder in \endorsed (or)
    \endorsed where catalina-home is apache tomcat6.x home i.e., C:\Apache Software Foundation\Apache Tomcat 6.0.26 in my case
    and catalina-base is tomcat instance i.e., C:\Documents and Settings\o404028\.netbeans\6.9\apache-tomcat-6.0.26_base in my case.
    It should fix.

    ReplyDelete
  13. It did solve my problem. NetBeans 6.9.1 and JDK 1.6_21. After I created 'endorsed' dir in JDK's lib folder and copied webservices-api from netbeans's provided Metro lib into it problem was solved.

    THNX

    ReplyDelete
  14. You are awesome!!! you saved me the big trouble. I have been trying this for last 2 days and going absolutely crazy on it.
    I added \endorsed in jre\lib but that didn't work. So I moved it under catalina_home and it worked like a charm.
    Thankyou so much once again.

    ReplyDelete
  15. HI, I have added the webservices-api.jar in:
    C:\Program Files\Java\jdk1.6.0_06\jre\lib\endorsed
    and also in my jboss C:\jboss-6.1.0.Final\lib\endorsed , but it still displays the same error: "Trying to override old definition of task apt." I took the jar from the metro 2.0, Does anyone have a suggestion for me?

    ReplyDelete

Individuals who comment on FromDev at regular basis, will be rewarded in Top Commenter section. (Comments are selectively moderated so please do not spam)

emo-but-icon

...

item