apt 警告:未找到注释处理器
我现在正在自学 Web 服务并尝试运行 helloWorld。我认为要设置所有网络服务,我需要运行 apt。
我像这样运行它:
apt HelloImpl.java -classpath /<path>/jsr181-api.jar
但我收到警告(见下文)。我还需要指定注释处理器吗?我认为 apt 命令应该生成几个文件,但没有发生(只是生成一个 .class 文件)。感谢您的帮助。
警告:
warning: No annotation processors found but annotations present.
1 warning
代码:
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 + "!";
}
}
额外问题:apt 的作用是什么?我假设它调用 javac?它是否还应该调用注释处理器?
更新:我正在关注的教程说:
The next step is to run apt on the above Java code, resulting in several artifacts:
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
我认为这就是 apt 应该产生的结果(假设我向它传递了正确的参数)。但是我认为我需要向它传递一个注释处理器(?)。不过,我真的只想使用默认的(Web 服务注释处理器)。
更新 2:也许我应该使用 asant 或 wsgen?我看了,但我的机器上没有这些。需要研究一下。也许我正在/正在使用的教程是错误的。以下是 asant 参考的链接: http://java .sun.com/webservices/docs/2.0/tutorial/doc/JAXWS3.html
I am just teaching myself about web services right now and trying to run a helloWorld. I think that to setup all of the web service stuff I need to run apt.
I am running it like this:
apt HelloImpl.java -classpath /<path>/jsr181-api.jar
But I am getting a warning (see below). Do I need to specify an annotation processor too? I think that the apt command is supposed to generate several files but that is not happening (just generating a .class file). Thanks for the help.
Warning:
warning: No annotation processors found but annotations present.
1 warning
Code:
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 + "!";
}
}
Bonus Question: What does apt do? I assume that it invokes javac? Is it supposed to also invoke a annotation processor?
Update: The tutorial that I am following says:
The next step is to run apt on the above Java code, resulting in several artifacts:
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
I think that this is what apt should be producing (assuming that I pass it the correct arguments). However I think that I need to pass it an annotation processor(?). I would really just like to use the default (web services annotation processor) though.
Update 2: Maybe I should be using asant or wsgen? I looked but I don't have either of these on my machine.. Something to look into.. Maybe the tutorial I am/was using is wrong. Here is a link to the asant reference: http://java.sun.com/webservices/docs/2.0/tutorial/doc/JAXWS3.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
apt
不是编译器。它处理源文件并调用 注释处理器视情况而定。引用入门...
您可以在源文件上运行 apt 以在构建时生成新的源文件或元数据文件。您可以运行
apt
通过javac
。Java 中的注释可以用于多种目的。并非所有这些都需要在构建时进行处理。有些充当标记,可以通过检测来在加载时转换类。大多数仅在运行时标记中使用,可供内省工具(如许多容器和依赖项注入器)使用。具体如何使用注释取决于它所来自的 API。 JEE5 教程介绍如何使用
WebService注释
。
apt
is not a compiler. It processes source files and invokes annotation processors as appropriate.To quote the Getting Started...
You might run apt on source files to generate new source files or metadata files at build time. You can run
apt
viajavac
.Annotations in Java can serve multiple purposes. Not all of them need to be processed at build time. Some serve as markers that can be used via instrumentation to transform classes at load time. Most are just used at runtime markers that can be used by introspection tools (like many containers and dependency injectors). Exactly how you use an annotation depends on the API it came from. The JEE5 tutorial describes how to use the
WebService
annotation.