Java Web service using Apt. Do I need an annotation processor? What is wrong?

别等时光非礼了梦想. 提交于 2020-01-04 14:22:56

问题


I have been trying to make a simple web service and have been following this tutorial . Unfortunately I am stuck. Here is what I have done so far:

1) I created this class:

package server;

import javax.jws.WebService;

@WebService
public class HelloImpl {

  /**
   * @param name
   * @return Say hello to the person.
   */
   public String sayHello(String name) {
     return "Hello, " + name + "!";
   }
}

2) I ran:

apt HelloImpl.java

3) I get this warning:

hostName[username:~/Desktop/webtest][534]% apt HelloImpl.java
warning: Annotation types without processors: [javax.xml.bind.annotation.XmlRootElement, javax.xml.bind.annotation.XmlAccessorType, javax.xml.bind.annotation.XmlType, javax.xml.bind.annotation.XmlElement]
1 warning

The apt command should (according to the tutorial) produce these files:

HelloServiceImpl.wsdl
schema1.xsd
classes/server/HelloImpl.class
classes/server/jaxrpc/SayHello.class
classes/server/jaxrpc/SayHelloResponse.class
classes/server/jaxrpc/SayHello.java
classes/server/jaxrpc/SayHelloResponse.java

This is what was generated when I called apt:

HelloImpl.java (not generated but it is still in the directory)
HelloImpl.class
server/jaxws/SayHello.cass
server/jaxws/SayHell.java
server/jaxws/SayHelloResponse.class
server/jaxws/SayHelloResponse.java

(missing:)

HelloServiceImpl.wsdl
schema1.xsd

(the paths are also slightly different)

I suspect that the warning is being generated and the other files are not being generated because I have "Annotation types without processors:".

I think that the warning indicates that it needs an annotation factory (processor). I know that you can specify what a factory by:

enter code here-cp Specify where to find user class files and annotation processor factories

I am just unsure of what factory to specify. (Or maybe I need to configure something differently).


回答1:


That 5 year old tutorial might be a bit out of date. jax-ws is the successor to jax-rpc. Though, maybe all you need is to run the wsgen tool instead of apt.

Take a look here for a mini tutorial In-process SOAP service server for Java



来源:https://stackoverflow.com/questions/2120045/java-web-service-using-apt-do-i-need-an-annotation-processor-what-is-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!