XDoclet is an extended Javadoc Doclet engine. It is a common Java tool that allows you to create your own javadoc @tags and use the Templet Engening in the XDoclet to generate source code or other files (eg XML Deployment Descriptors) based on the TEMPLET ENGING in the xdoclet.
I don't want to say more about the architecture and working principle of XDoclet, you can google. I just want to quickly pick up the xdoclet through a simple instance. Because I found that when I learned a new knowledge point, there are a lot of concepts, but the example is very small, it is difficult to quickly digest conceptual things through instances. Instead of saying a lot of books, it is better to give me an example, so that I try to figure it out.
Before watching this article, it is best to be familiar with Ant.
First, download, installation, and configuration
1. Software required
● Ant 1.6.2
http://ant.apache.org
download
http://mirror.apache.or.kr/ant/binaries/apache-ant-1.6.2-bin.zip
● xDoclet 1.2.2
http://xdoclet.sourceforge.net/xdoclet/
download
http://prdownloads.sourceforge.net/xdoclet/xdoclet-bin-1.2.2.zip?download
● Tomcat 5.0.28
Http://jakarta.apache.org/tomcat/
download
http://apache.justdn.org/jakarta/tomcat-5/v5.0.28/bin/jakarta-tomcat-5.0.28.zip
2. Installation
F: / j2sdk jdk directory
F: / java / ant Ant catalog
F: / java / xdoclet xdoclet directory
F: / java / jakarta-tomcat tomcat directory
Here, it is important to set up Ant_home in the environment variable, and point to the ANT installation directory, but also add "% Ant_home% / bin in the PATH variable;" can be referenced
Java environment variable settings.
Second, a simple example
Writing code
Create a D: / XDocletsample directory, establish 3 files in accordance with the following structure.
D: / xdocletsample/src/javamxj/helloservlet.java
/ *
* @author javamxj (9cbs blog) creation date 2005-1-7
* /
Package javamxj;
Import javax.servlet. *;
Import javax.servlet.http. *;
/ **
* @ Web.Servlet name = "Helloservlet"
* Display-name = "Hello Servlet"
* Load-on-startup = "1"
* @ Web.Servlet-init-param name = "Hello"
* Value = "$ {hello.servlet}"
* @ Web.Servlet-maping url-pattern = "/ hello / *"
* /
Public class helloservlet extends httpservlet {public void init (servletconfig config) throws servletexception {
// Get initialization parameters from web.xml
Super.init (config);
}
Protected Void Doget (httpservletRequest Request,
HttpservletResponse response) Throws servletexception,
Java.io.ioException {
ServletConfig Config = this.getServletConfig ();
String h = config.getinitParameter ("Hello");
Try {
// Set the document type first
Response.setContentType ("text / html; charset = GBK");
// Get output flow
Java.io.printwriter out = response.getwriter ();
Out.println ("
Out.println ("
Out.println ("Hello:" H);
Out.println (" h1> body> html>");
Out.close ();
} catch (exception e) {
Throw new servletexception (e);
}
}
}
D: / xdocletsample/build.xml
XML Version = "1.0" encoding = "GBK"?>
path>
fileset>
path>
target>
Name = "WebDoclet" ClasspathRef = "xdoclet.classpath" ClassName = "xdoclet.modules.web.webdoclettask" /> WebDoclet> target> javac> target> provject> D: / xdocletsample/build.properties ######################################################################################################################################################################################################################################################################################## # # File Name: Build.properties # Author: 9CBS javamxj # # Web server directory Tomcat.home = f: / java / jakarta-tomcat # xdoclet directory xdoclet.home = f: / java / xdoclet # w 的 临 临 directory Dist.dir =. / dist # 源 文件 文件 directory Src.dir =. / src # 发布 程序 名 app.name = HelloWeb # Servlet parameter, you can change Hello.Servlet = Javamxj Blog You can change the directory directory of Tomcat, XDoclets in the build.properties property file according to your own settings. 2. Run the program ● Open an MS-DOS window to switch to the D: / XDocletsample directory, enter the ANT command: ● The Tomcat server is then started, open the browser window, type the address: http: // localhost: 8080 / helloweb / hello / Open the build.properties file, will " Hello.servlet = javamxj blog "Statement is modified" Hello.servlet = 9cbs, then save. ● In MS-DOS, enter "Ant -DxDoclet.Force = true" ● Refresh the browser window, the following: Ok, this is just a simple xdoclet instance. Third, how is Web.xml generated Note that there is no, here doesn't write a web.xml file, but you can find a web.xml file from the D: / XDocletsample / DIST / Web-Inf directory. The content is as follows (for easy browsing, I have deleted the comment): D: / xdocletsample/dist/web-inf/web.xml Maybe you will think that this is nothing, it is not very simple, but when using XDoclet to develop EJB, you will make more experience in its superiority. The next article talks about how to develop EJB. Fourth, reference information: article: Use xDoclet to improve the reuse of J2EE components (This is a tutorial on the IBM website. This article is written by it for blueprint. Need registration to log in.) http://www2.tw.ibm.com/developerWorks/Tutorial/content/java/t20031110_Xdoclets.htm (Ibida, this is the article on China's Taiwan website, traditional, no registration) XDoclet learning notes (This is a series, there are 4 articles, and the principle of xdoclet is relatively thorough.) books: MANNING - XDoclet in Action Others: XDoclet itself comes with documents and instances. (It is recommended to look at it, anyway, I often use it)