0.10.0
Copyright © 2009, 2010, 2011, 2012 Lunatech Labs, Stéphane Épardaud
Abstract
jax-doclets is a set of JavaDoc doclets for the Java Extension APIs.
This is pre-release software, please bear with it.
This book is produced by the Wikbook tool. Wikbook is an open source project for converting wiki files into a set of docbook files.
jax-doclets allows you to generate JavaDoc documentation for specific Java annotation-based extensions such as:
The goal of jax-doclets is to let you write documentation for your JAX-RS API, JAXB structures and JPA model in JavaDoc, where it belongs, where it is maintainable, and produce a quality JavaDoc-style documentation.
jax-doclets is an open-source project maintained by Lunatech Labs.
Home page | http://www.lunatech-labs.com/content/jax-doclets |
Download | https://github.com/FroMage/jax-doclets/downloads |
Issue Tracker | https://github.com/FroMage/jax-doclets/issues |
Source Control Management | https://github.com/FroMage/jax-doclets |
Here is an example of documented JAX-RS and JAXB code:
Example 1.1. Example of documented JAX-RS and JAXB code
package com.lunatech.doclets.jax.test; import javax.ws.rs.*; import javax.xml.bind.annotation.*; /** * An example JAX-RS resource */ @Path("/example") @Produces( { "application/xml", "application/*+xml" }) public class JAXRSExample { /** * An example resource */ @XmlRootElement public static class JAXBExample { /** * The resource ID */ @XmlID @XmlElement String id; /** * The example contents */ @XmlValue String contents; /** * An optional attribute */ @XmlAttribute String type; } /** * Gets an example resource * * @param id * the example id * @param type * the type of resource we prefer * @param startIndex * the start index * @return an example resource suitable for the given parameters * @HTTP 404 if there is no such example resource * @RequestHeader X-Example-Auth the authentication header * @ResponseHeader Location a pointer to the example details */ @Path("{id}") @GET public JAXBExample getExample(@PathParam("id") String id, @MatrixParam("type") String type, @QueryParam("start") int startIndex) { return new JAXBExample(); } }
Here is an example of documented JPA code:
Example 1.2. Example of documented JPA code
package com.lunatech.doclets.jax.test.jpa; import java.util.List; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Transient; /** * This is the order type. * * @author stephane */ @Entity public class Order { /** * This is my ID and I love it */ @Id @GeneratedValue public Long id; /** * Column with an explicit name */ @Column(name = "column_with_name") public String columnWithName; /** * Column with an annotation */ @Column public String columnWithAnnotation; /** * Column with no annotation */ public String columnWithoutAnnotation; /** * Transient property */ public transient String transientColumn; /** * Transient property */ @Transient public String transientAnnotatedColumn; /** * A Bill */ @JoinColumn(name = "bill_id") @OneToOne public Bill bill; /** * A list of Orderlines */ @OneToMany(mappedBy = "order") public List<Orderline> orderlineList; /** * A set of Orderlines */ @OneToMany(mappedBy = "order") public Set<Orderline> orderlineSet; /** * A set of Items, via a link table */ @JoinTable(name = "order2item", joinColumns = @JoinColumn(name = "item_id"), inverseJoinColumns = @JoinColumn(name = "order_id")) @ManyToMany public Set<Item> itemSet; }
The jax-doclets are run by JavaDoc either as standalone, via ant or using Maven.
Note | |
---|---|
Since the JAX-RS supports links to JAXB documentation, you should first run the JAXB doclet, then the JAX-RS doclet using the
|
You can use the following command to run the JAXB doclet on your code:
javadoc -doclet com.lunatech.doclets.jax.jaxb.JAXBDoclet \ -docletpath lib/jax-doclets-0.10.0.jar \ com.lunatech.doclets.jax.test
You can use the following command to run the JAX-RS doclet on your code:
javadoc -doclet com.lunatech.doclets.jax.jaxrs.JAXRSDoclet \ -docletpath lib/jax-doclets-0.10.0.jar \ com.lunatech.doclets.jax.test
You can use the following ant XML to run the JAXB doclet on your code:
<target depends="jars" description="Run the JAXB doclet" name="doc-jaxb"> <javadoc doclet="com.lunatech.doclets.jax.jaxb.JAXBDoclet" docletpath="lib/jax-doclets-0.10.0.jar"> <package name="com.lunatech.doclets.jax.test.*"/> </javadoc> </target>
You can use the following ant XML to run the JAX-RS doclet on your code:
<target depends="jars" description="Run the JAXRS doclet" name="doc-jaxrs"> <javadoc doclet="com.lunatech.doclets.jax.jaxrs.JAXRSDoclet" docletpath="lib/jax-doclets-0.10.0.jar"> <package name="com.lunatech.doclets.jax.test.*"/> </javadoc> </target>
You can use the following ant XML to run the JPA doclet on your code:
<target depends="jars" description="Run the JPA doclet" name="doc-jpa"> <javadoc doclet="com.lunatech.doclets.jax.jpa.JPADoclet" docletpath="lib/jax-doclets-0.10.0.jar"> <package name="com.lunatech.doclets.jax.test.*"/> </javadoc> </target>
You can use the following Maven POM extract to run the JAXB doclet on your code:
<reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.7</version> <reportSets> <reportSet> <id>jaxb</id> <configuration> <doclet>com.lunatech.doclets.jax.jaxb.JAXBDoclet</doclet> <docletArtifacts> <docletArtifact> <groupId>com.lunatech.jax-doclets</groupId> <artifactId>doclets</artifactId> <version>0.10.0</version> </docletArtifact> </docletArtifacts> </configuration> <reports> <report>javadoc</report> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting>
Which you run with:
$ mvn site
You can use the following Maven POM extract to run the JAX-RS doclet on your code:
<reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.7</version> <reportSets> <reportSet> <configuration> <doclet>com.lunatech.doclets.jax.jaxrs.JAXRSDoclet</doclet> <docletArtifacts> <docletArtifact> <groupId>com.lunatech.jax-doclets</groupId> <artifactId>doclets</artifactId> <version>0.10.0</version> </docletArtifact> </docletArtifacts> </configuration> <reports> <report>javadoc</report> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting>
Which you run with:
$ mvn site
You can use the following Maven POM extract to run the JPA doclet on your code:
<reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.7</version> <reportSets> <reportSet> <id>jpa</id> <configuration> <doclet>com.lunatech.doclets.jax.jpa.JPADoclet</doclet> <docletArtifacts> <docletArtifact> <groupId>com.lunatech.jax-doclets</groupId> <artifactId>doclets</artifactId> <version>0.10.0</version> </docletArtifact> </docletArtifacts> </configuration> <reports> <report>javadoc</report> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting>
Which you run with:
$ mvn site
These parameters are valid for all jax-doclets
These parameters are only valid for the JAX-RS doclet
Parameter | Function |
---|---|
-jaxrscontext url
| The URL path to your RESTful API, if there is a prefix prepended to it on your deploy site. |
-disablehttpexample
| Disables the generated HTTP examples. |
-disablejavascriptexample
| Disables the generated JavaScript examples. |
These parameters are only valid for the JAXB doclet
Parameter | Function |
---|---|
-disablejsontypename
| If you want to hide the serialised type name from the JSON examples. |
-disablexmlexample
| Disables the generated XML examples. |
-disablejsonexample
| Disables the generated JSON examples. |
If you do not specify a stylesheet, one will be provided for you that closely matches the default JavaDoc style. If you do specify a stylesheet with the -stylesheet
parameter, it will be copied to the stylesheet named doclet.css
and the default JavaDoc stylesheet will be available as default-doclets.css
which means you can write your stylesheet like this to extend the default stylesheet without having to restyle everything:
@IMPORT url("default-doclet.css"); table.info .TableCaption, td.NavBarCell1 { background: #EEEEEE; } td.NavBarCell1 table th.selected { background-color: #61911B; } img.logo { margin: 1em; border: none; } a { color: #61911B; } a:visited { color: #3F5E12; }
Note that wherever possible we´ve stuck with the JavaDoc CSS class names so you can reuse your existing JavaDoc stylesheets.
The JAX-RS doclet generates documentation for your RESTful service based on JAX-RS annotations and JavaDoc comments on your JAX-RS resource methods.
JavaDoc is read either on the JAX-RS resource methods, or their interface. Only method-level JavaDoc is used. Documentation for a given RESTful URL is taken from the method annotated with @GET
, @HEAD
, @POST
, @PUT
or @DELETE
for that URL (in order of preference).
JAX-RS resource locators are supported.
Note | |
---|---|
Since the JAX-RS supports links to JAXB documentation, you should first run the JAXB doclet, then the JAX-RS doclet using the
|
The following standard JavaDoc tags are supported on resource methods:
Tag | Function |
---|---|
@param name doc
| This is used to document the corresponding resource method parameters annotated with @PathParam , @QueryParam or @MatrixParam . Can be used at most once per parameter name. |
@return doc
| Documents the entity returned from this resource method. Can only be used once. |
The following specific JavaDoc tags are supported on resource methods:
Tag | Function |
---|---|
@HTTP code doc
| This is used to document the codes that the method can return. Can be used multiple times. |
@inputWrapped fq-classname
| Specifies the real type of input when declared as a String parameter. Can only be used once. |
@returnWrapped fq-classname doc
| Used in place of @return when output type is String , void or Response to specify the real type of output and documentation for each possible type. Can be used multiple times. |
@RequestHeader header doc
| This is used to document HTTP request headers. Can be used multiple times. |
@ResponseHeader header doc
| This is used to document HTTP response headers. Can be used multiple times. |
@include file
| Includes the specified relative file in the resource documentation. Can be used multiple times. |
The following standard JAX-RS annotations are supported on resource methods or classes:
@Path
@PathParam
@FormParam
@CookieParam
@HeaderParam
@QueryParam
@MatrixParam
@Produces
@Consumes
@Context
(ignored)
The JAXB doclet generates documentation for your XML schema based on JAXB annotations and JavaDoc comments on your JAXB classes.
JavaDoc is read either on the JAXB properties (getter methods or fields), or their interface (only for the getters) as well as on the JAXB classes.
Note | |
---|---|
Since the JAX-RS supports links to JAXB documentation, you should first run the JAXB doclet, then the JAX-RS doclet using the
|
There are no standard JavaDoc tags supported. Everything comes from JavaDoc comments.
The following standard JAXB annotations are supported on properties or classes:
@XmlAccessorType
@XmlRootElement
@XmlElement
@XmlElementWrapper
@XmlAttribute
@XmlValue
@XmlID
@XmlIDREF
@XmlTransient
(ignored)
The following Java types have a special mapping in XML:
Type | XML mapping |
---|---|
java.lang.String
|
xsd:string
|
java.lang.Character , char
|
xsd:string
|
java.lang.Date
|
xsd:datetime
|
java.lang.Integer , int
|
xsd:int
|
java.lang.Long , long
|
xsd:long
|
java.lang.Short , short
|
xsd:short
|
java.lang.Byte , byte
|
xsd:byte
|
java.lang.Float , float
|
xsd:float
|
java.lang.Double , double
|
xsd:double
|
java.lang.Boolean , boolean
|
xsd:boolean
|
java.lang.Object
|
xsd:any
|
java.lang.Enum
| List of enum values |
java.util.Collection
|
xsd:list
|
Any other type is taken to be either a Java type or a JAXB type, for whom proper links will be generated.
The JPA doclet generates documentation for your data model based on JPA annotations and JavaDoc comments on your JPA classes.
There are no standard JavaDoc tags supported. Everything comes from JavaDoc comments.
The following standard JPA annotations are supported on classes or properties:
@Entity
@Id
@ManyToMany
@OneToMany
@ManyToOne
@OneToOne
@Table
@Transient
@GeneratedValue
@Id
@Lob