分享
 
 
 

readAppfuse-Ant任务

王朝java/jsp·作者佚名  2006-01-31
窄屏简体版  字體: |||超大  

★ appfuse ant setup执行过程

v 建立数据库:db-create,根据脚本文件Mysql-create,建立数据库

v clean and prepare:清除和建立目录

v 建立hibernate映射文件:hibernatedoclet,根据POJO,建立hibernate映射文件。

注:appfuse中的ORM,是现手工建立POJO,然后利用工具根据POJO生成映射文件,

数据库表等。POJO存储在org/appfuse/model下,生成的映射文件存储在

Build/Dao/gen下。使用xdoclet.modules.hibernate.HibernateDocletTask工具

v 编译dao:compile-dao,调用compile-module编译dao目录下的类文件

v package-dao:Dao打包

v db-prepare:根据hiberante映射文件,建立数据库表,

使用net.sf.hibernate.tool.hbm2ddl.SchemaExportTask工具

v db-load:利用dbunit工具,根据metadata/sql/sample-data.xml,向数据库表中插

入数据

v setup-tomcat:拷贝metadata/conf/tomcat-context.xml

到${tomcat.home}/conf/Catalina/localhost/appfuse.xml,还拷贝JDBC jar和jta.jar到tomcat。

v compile-service:编译service下的类

v copy-resources: 拷贝应用需要的各种配置文件到build\web\classes和

build\appfuse\WEB-INF,而且在此任务中会进行中文转换码工作,借助JDK的native2ascii工具将资源文件ApplicationResources_zh_CN.properties中的内容进行转码。

v gen-forms: 利用xdoclet 和struts_form.xdt,根据module目录中的POJO生成

Struts的ActionFrom

v compile-web:编译web目录中的类,appfuse中的web服务类是不被打包成jar文

件的,直接放在WEB-INF/class目录下调用。

v webdoclet:利用xdoclet.modules.web.WebDocletTask工具,生成了web.xml、

appfuse.tld、struts-config.xml 、struts_config_xml.xdt 、validation.xml 、

validation_xml.xdt等文件

BEGIN: Buildfile: build.xml

v init: defines custom task

v db-create: 建立数据库,授予用户访问权限

<!-- =================================================================== -->

<!-- The "db-create" target creates a database based on properties -->

<!-- from the database.properties file -->

<!-- =================================================================== -->

Ø Mysql-create(建立数据库脚本)的内容:

create database if not exists appfuse;

grant all privileges on appfuse.* to test@"%" identified by "test";

grant all privileges on appfuse.* to test@localhost identified by "test";

Ø运行结果:

[echo] Detected MySQL, creating database...

[echo] Creating database with: mysql-create.sql

[echo] URL: jdbc:mysql://localhost/mysql

[sql] Executing file: E:\app\appfuse\metadata\sql\mysql-create.sql

[sql] 3 of 3 SQL statements executed successfully

v clean:删除构建、发布目录和database.properties

Ødatabase.properties(hibernate环境属性)的内容

#Hibernate Configuration for JUnit tests

#Mon Jun 20 00:08:25 CST 2005

hibernate.connection.username=test

dao.type=hibernate

hibernate.connection.password=test

hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect

hibernate.connection.url=jdbc\:mysql\://localhost/appfuse?autoReconnect\=true&useUnicode\=true&characterEncoding\=utf-8

hibernate.connection.show_sql=true

hibernate.connection.driver_class=com.mysql.jdbc.Driver

Ø运行结果:

[echo] Cleaning build and distribution directories

[delete] Deleting directory E:\app\appfuse\build

[delete] Deleting directory E:\app\appfuse\dist

[delete] Deleting: E:\app\appfuse\database.properties

build.properties.missing:

v prepare:

Ø 运行结果:

[echo] Preparing target directory 'E:\app\appfuse/build/appfuse'

[mkdir] Created dir: E:\app\appfuse\build\appfuse

[mkdir] Created dir: E:\app\appfuse\build\appfuse\WEB-INF

[mkdir] Created dir: E:\app\appfuse\dist\webapps

v hibernatedoclet:

<!-- =================================================================== -->

<!-- The "hibernatedoclet" target generates Hibernate mapping files -->

<!-- based on XDoclet marked-up Plain Old Java Object (POJO) -->

<!-- =================================================================== -->

Ø 任务定义

<target name="hibernatedoclet" depends="prepare"

unless="hibernatedoclet.unnecessary"

description="Generate Hibernate mapping files">

<taskdef name="hibernatedoclet"

classname="xdoclet.modules.hibernate.HibernateDocletTask"

classpathref="xdoclet.classpath"/>

<!-- generate hibernate files -->

<hibernatedoclet

destdir="${build.dir}/dao/gen"

mergedir="metadata/dao"

excludedtags="@version,@author"

addedtags="@xdoclet-generated at ${TODAY}"

force="${xdoclet.force}">

<fileset dir="src/dao"/>

<hibernate validatexml="true" version="2.0"/>

</hibernatedoclet>

</target>

Ø 运行结果:

[hibernatedoclet] (XDocletMain.start 47 ) Running <hibernate/>

[hibernatedoclet] Generating mapping file for org.appfuse.model.User.

[hibernatedoclet] org.appfuse.model.User

[hibernatedoclet] Generating mapping file for org.appfuse.model.UserCookie.

[hibernatedoclet] org.appfuse.model.UserCookie

[hibernatedoclet] Generating mapping file for org.appfuse.model.Role.

[hibernatedoclet] org.appfuse.model.Role

v compile-dao:调用compile-module编译dao目录下的类文件,包括测试类。

v compile-module:编译工作的主任务,其他具体编译工作以参数调用其完成编译工作。

Ø 任务定义:

<target name="compile-module">

<!-- Inputs: module, compile.classpath, test.classpath -->

<echo level="info">Compiling ${module}...</echo>

<mkdir dir="${build.dir}/${module}/classes"/>

<mkdir dir="${test.dir}/${module}/classes"/>

<property name="excludes" value=""/>

<property name="additional.src.dirs" value=""/>

<javac srcdir="src/${module};${additional.src.dirs}"

destdir="${build.dir}/${module}/classes"

debug="${compile.debug}"

deprecation="${compile.deprecation}"

optimize="${compile.optimize}"

classpathref="compile.classpath"/>

<javac srcdir="test/${module}"

destdir="${test.dir}/${module}/classes"

debug="true">

<classpath>

<path refid="test.classpath"/>

<path location="${build.dir}/${module}/classes"/>

</classpath>

</javac>

</target>

Ø 运行结果:

[echo] Compiling dao...

[mkdir] Created dir: E:\app\appfuse\build\dao\classes

[mkdir] Created dir: E:\app\appfuse\build\test\dao\classes

[javac] Compiling 15 source files to E:\app\appfuse\build\dao\classes

[javac] Note: E:\app\appfuse\src\dao\org\appfuse\model\User.java uses unchecked or unsafe operations.

[javac] Note: Recompile with -Xlint:unchecked for details.

[javac] Compiling 5 source files to E:\app\appfuse\build\test\dao\classes

[javac] Note: E:\app\appfuse\test\dao\org\appfuse\dao\BaseDAOTestCase.java uses unchecked or unsafe operations.

[javac] Note: Recompile with -Xlint:unchecked for details.

v package-dao:Dao打包

Ø 运行结果:

[copy] Copying 1 file to E:\app\appfuse\build\dao\gen

[jar] Building jar: E:\app\appfuse\dist\appfuse-dao.jar

v db-prepare:

<!-- =================================================================== -->

<!-- The "db-prepare" target generates the database schema and creates -->

<!-- tables based on the mapping files -->

<!-- =================================================================== -->

Ø 任务定义:

<target name="db-prepare" depends="clean,package-dao"

description="creates database tables">

<taskdef name="schemaexport"

classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">

<classpath>

<path refid="xdoclet.classpath"/>

<path refid="hibernate.classpath"/>

</classpath>

</taskdef>

<antcall target="generate.database.properties"/>

<schemaexport quiet="no" text="no" drop="no" delimiter=";"

properties="database.properties" output="create-tables.sql">

<fileset dir="${build.dir}/dao/gen" includes="**/*.hbm.xml"/>

</schemaexport>

</target>

v generate.database.properties:

Ø 任务定义:

<target name="generate.database.properties">

<echo>generating database.properties from properties.properties</echo>

<propertyfile comment="Hibernate Configuration for JUnit tests"

file="${basedir}/database.properties">

<entry key="hibernate.dialect" value="${hibernate.dialect}"/>

<entry key="hibernate.connection.driver_class" value="${database.driver_class}"/>

<entry key="hibernate.connection.url" value="${database.url}"/>

<entry key="hibernate.connection.username" value="${database.username}"/>

<entry key="hibernate.connection.password" value="${database.password}"/>

<entry key="hibernate.connection.show_sql" value="${database.show_sql}"/>

<entry key="dao.type" value="${dao.type}"/>

</propertyfile>

<replace file="database.properties" token="amp;" value=""/>

<property file="database.properties"/>

</target>

Ø db-prepare运行结果:

[echo] generating database.properties from build.properties

[propertyfile] Creating new property file: E:\app\appfuse\database.properties

[schemaexport] (cfg.Environment 478 ) Hibernate 2.1.7

[schemaexport] (cfg.Environment 507 ) hibernate.properties not found

[schemaexport] (cfg.Environment 538 ) using CGLIB reflection optimizer

[schemaexport] (cfg.Environment 567 ) using JDK 1.4 java.sql.Timestamp handling

[schemaexport] (cfg.Configuration 169 ) Mapping file: E:\app\appfuse\build\dao\gen\org\appfuse\model\Role.hbm.xml

[schemaexport] (cfg.Binder 230 ) Mapping class: org.appfuse.model.Role -> role

[schemaexport] (cfg.Configuration 169 ) Mapping file: E:\app\appfuse\build\dao\gen\org\appfuse\model\User.hbm.xml

[schemaexport] (cfg.Binder 230 ) Mapping class: org.appfuse.model.User -> app_user

[schemaexport] (cfg.Binder 572 ) Mapping collection: org.appfuse.model.User.roles -> user_role

[schemaexport] (cfg.Configuration 169 ) Mapping file: E:\app\appfuse\build\dao\gen\org\appfuse\model\UserCookie.hbm.xml

[schemaexport] (cfg.Binder 230 ) Mapping class: org.appfuse.model.UserCookie -> user_cookie

[schemaexport] (dialect.Dialect 86 ) Using dialect: net.sf.hibernate.dialect.MySQLDialect

[schemaexport] (cfg.Configuration 632 ) processing one-to-many association mappings

[schemaexport] (cfg.Configuration 641 ) processing one-to-one association property references

[schemaexport] (cfg.Configuration 666 ) processing foreign key constraints

[schemaexport] (cfg.Configuration 632 ) processing one-to-many association mappings

[schemaexport] (cfg.Configuration 641 ) processing one-to-one association property references

[schemaexport] (cfg.Configuration 666 ) processing foreign key constraints

[schemaexport] (hbm2ddl.SchemaExport 98 ) Running hbm2ddl schema export

[schemaexport] (hbm2ddl.SchemaExport 112 ) writing generated schema to file: create-tables.sql

[schemaexport] (hbm2ddl.SchemaExport 117 ) exporting generated schema to database

[schemaexport] (connection.DriverManagerConnectionProvider 42 ) Using Hibernate built-in connection pool (not for production use!)

[schemaexport] (connection.DriverManagerConnectionProvider 43 ) Hibernate connection pool size: 20

[schemaexport] (connection.DriverManagerConnectionProvider 77 ) using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/appfuse?autoReconnect=true&useUnicode=true&characterEncoding=utf-8

[schemaexport] (connection.DriverManagerConnectionProvider 78 ) connection properties: {user=test, password=test, show_sql=true}

[schemaexport] alter table user_role drop foreign key FK143BF46A14048CB4;

[schemaexport] alter table user_role drop foreign key FK143BF46AF02988D6;

[schemaexport] drop table if exists user_role;

[schemaexport] drop table if exists app_user;

[schemaexport] drop table if exists user_cookie;

[schemaexport] drop table if exists role;

[schemaexport] create table user_role (

[schemaexport] username varchar(20) not null,

[schemaexport] role_name varchar(20) not null,

[schemaexport] primary key (username, role_name)

[schemaexport] );

[schemaexport] create table app_user (

[schemaexport] username varchar(20) not null,

[schemaexport] version integer not null,

[schemaexport] password varchar(255) not null,

[schemaexport] first_name varchar(50) not null,

[schemaexport] last_name varchar(50) not null,

[schemaexport] address varchar(150),

[schemaexport] city varchar(50) not null,

[schemaexport] province varchar(100),

[schemaexport] country varchar(100),

[schemaexport] postal_code varchar(15) not null,

[schemaexport] email varchar(255) not null unique,

[schemaexport] phone_number varchar(255),

[schemaexport] website varchar(255),

[schemaexport] password_hint varchar(255),

[schemaexport] primary key (username)

[schemaexport] );

[schemaexport] create table user_cookie (

[schemaexport] id bigint not null,

[schemaexport] username varchar(30) not null,

[schemaexport] cookie_id varchar(100) not null,

[schemaexport] date_created datetime not null,

[schemaexport] primary key (id)

[schemaexport] );

[schemaexport] create table role (

[schemaexport] name varchar(20) not null,

[schemaexport] version integer not null,

[schemaexport] description varchar(255),

[schemaexport] primary key (name)

[schemaexport] );

[schemaexport] alter table user_role add index FK143BF46A14048CB4 (role_name), add constraint FK143BF46A14048CB4 foreign key (role_name) references role (name);

[schemaexport] alter table user_role add index FK143BF46AF02988D6 (username), add constraint FK143BF46AF02988D6 foreign key (username) references app_user (username);

[schemaexport] create index user_cookie_username_cookie_id on user_cookie (username, cookie_id);

[schemaexport] (hbm2ddl.SchemaExport 160 ) schema export complete

[schemaexport] (connection.DriverManagerConnectionProvider 143 ) cleaning up connection pool: jdbc:mysql://localhost/appfuse?autoReconnect=true&useUnicode=true&characterEncoding=utf-8

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有