Use XDoclet with ant-simple example

Source: Internet
Author: User

1. Unzip XDoclet to D:/XDoclet/xdoclet-plugins-1.0.3

2. Create a com. XK. OA. Model package, create a user class under the package, and use javadoc annotations.

Package com. XK. OA. model;

/**
*
* @ Author Administrator
* @ Hibernate. Class table = "t_user"
*/
Public class user
{
/**
*
* @ Hibernate. ID generator-class = "native"
*/
Private integer ID;
/**
*
* @ Hibernate. Property
*/
Private string username;
/**
*
* @ Hibernate. Property
*/
Private string password;

Public integer GETID ()
{
Return ID;
}

Public void setid (integer ID)
{
This. ID = ID;
}

Public String GetUserName ()
{
Return username;
}

Public void setusername (string username)
{
This. Username = username;
}

Public String GetPassword ()
{
Return password;
}

Public void setpassword (string password)
{
This. Password = password;
}

}

3. Create a build. xml file in the src directory of the project.

<? XML version = "1.0" encoding = "UTF-8"?>

<Project name = "oaoa "default = "generate the hibernate configuration file" basedir = ".">

<Property name = "src. dir" value = "$ {basedir}/src"/>
<! --
<Property name = "build. dir" value = "$ {basedir}/bin"/>
<Property name = "webapp. dir" value = "$ {basedir}/src/webroot"/>
-->
<! -- The directory where XDoclet is extracted -->
<Property name = "XDoclet. Home" value = "D:/XDoclet/xdoclet-plugins-1.0.3"/>

<! -- Build classpath -->
<Path id = "XDoclet. task. classpath">
<Fileset dir = "$ {XDoclet. Home}/lib">
<Include name = "**/*. Jar"/>
</Fileset>
<Fileset dir = "$ {XDoclet. Home}/plugins">
<Include name = "**/*. Jar"/>
</Fileset>
</Path>
<Taskdef
Name = "XDoclet"
Classname = "org. XDoclet. Ant. xdoclettask"
Classpathref = "XDoclet. task. classpath"
/>

<Target name = "generate a hibernate configuration file">
<XDoclet>
<Fileset dir = "$ {SRC. dir}/COM/XK/OA/model">
<Include name = "**/*. Java"/>
</Fileset>
<Component
Classname = "org. XDoclet. plugin. hibernate. hibernateconfigplugin"
Destdir = "$ {SRC. dir }"
Version = "3.0"
Hbm2ddlauto = "Update"
Jdbcurl = "JDBC: mysql: // 127.0.0.1/oa_test"
Jdbcdriver = "com. MySQL. JDBC. Driver"
Jdbcusername = "root"
Jdbcpassword = "root"
Dialect = "org. hibernate. dialect. mysqldialect"
Showsql = "true"
/>
</XDoclet>
</Target>
<Target name = "generate a hibernate ing file">
<XDoclet>
<Fileset dir = "$ {SRC. dir}/COM/XK/OA/model">
<Include name = "**/*. Java"/>
</Fileset>
<Component
Classname = "org. XDoclet. plugin. hibernate. hibernatemappingplugin"
Version = "3.0"
Destdir = "$ {SRC. dir }"
/>
</XDoclet>
</Target>
</Project>

4. Show ant

1. Window --> show View --> Other

2. Select ant --> OK

3. Now the ant view will appear below

4. Click Add buildfiles in to add build. xml.

After being added, the ant view displays build. xml

5. Double-click the file to run and generate the user. HBM. xml file andHibernate. cfg. xml file

User. HBM. xml file

Hibernate. cfg. xml file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.