Thursday, September 11, 2008

Using annotated classes as web method params or return types

Some time back one of my friends was writing a web service in which certain web methods either returned or received Entity classes as parameters. When ever the wsgen command was fired an error as below was generated:
C:\eclipse\workspace\TopLinkExample\bin>wsgen -cp . service.TopLinkImpl .\org\acme\entity\Order.class: warning: Cannot find annotation method 'name()' i n type 'javax.persistence.Table': class file for javax.persistence.Table not fou nd .\org\acme\entity\Order.class: warning: Cannot find annotation method 'strategy( )' in type 'javax.persistence.GeneratedValue': class file for javax.persistence. GeneratedValue not found Problem encountered during annotation processing; see stacktrace below for more information. java.lang.NullPointerException at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAP.i sSubtype(WebServiceAP.java:418) at...
After pondering for a while we figured out that the required classes (persistence related jars) were not in the class path.
So the following command got our stuff working:
C:\eclipse\workspace\TopLinkExample\bin>set CLASSPATH=%CLASSPATH%;C:\eclipse\wor kspace\TopLinkExample\lib\ejb3-persistence.jar;C:\eclipse\workspace\TopLinkExamp le\lib\jboss-ejb3x.jar;C:\eclipse\workspace\TopLinkExample\lib\toplink-essential s.jar;.; C:\eclipse\workspace\TopLinkExample\bin>wsgen -cp %CLASSPATH%;. service.TopLinkImpl
Even though this seems to be a very simple problem, during the time we were searching for the solution, we found that most of the people had this problem and didn't know the solution, whereas the -cp . in the wsgen command was going unnoticed.

1 comment:

  1. I had exactly the same problem. Thanks for the solution. I got compilererrors in my webapp when building with ant. All I had to do was to add the persistence jar to my webapps building classpath.

    ReplyDelete