This is kind of newbie issue but (1) it stumped me (2) no one else blogged a solution and (3) it seems so simple.
Background: I am creating a web service in Eclipse but Eclipse doesn't recognize the "@WebService" annotation. I don't know if this an Eclipse feature I need to enable or some plug-in I have to install?
- I type a web service annotation like @WebService to mark a Java class as a web service.
- Eclipse presents the annotation in red and floats the message 'WebService cannot be resolved to a type'
- I figure I have to add some plug-in or something and google around awhile but nothing is helpful.
- I find some references that I need to have J2EE classes in my classpath
Answer:Annotations are actually interpreted, they're classes and you need to import the correct (javax.ws) library before you reference one. (This is not really an Eclipse issue).
- Find a distribution jar that has the WebService class
- Locate Apache geronimo-ws-metadata_2.0_spec-1.1.2.jar, jsr181.jar or J2ee.jar
- Add one of the jars to the project classpath
- Add an import statement import javax.jws.WebService to your java class
- Done, now Eclipse understands the @WebService annotation
BTW:- You'll have the same issue when you enter the @WebParam annotation (and whatever other annotations you might use), except you now have to import javax.jws.WebParam.
- The SOAPBinding annotation is in package javax.jws.soap.SOAPBinding.
Notes:- The classes for the Web Services annotations are supplied in a number of common jar files (e.g. the geronimo jar mentioned above is not the only source of the annotations classes):
- The JDK distribution jsr181.jar
- The J2EE distribution javaee.jar
- I'm sure all this is pathetic to those who know web services, but it stumped me awhile, plus I munged up my Eclipse installation trying to find an alternate project type or plugin to configure to get the annotation to be recognized.