views:

118

answers:

1

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

+1  A: 

apt is not a compiler. It processes source files and invokes annotation processors as appropriate.

To quote the Getting Started...

The command-line utility apt, annotation processing tool, finds and executes annotation processors based on the annotations present in the set of specified source files being examined.

You might run apt on source files to generate new source files or metadata files at build time. You can run apt via javac.

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.

McDowell