网络相册开发(6)——ant 自动生成数据库

本文介绍了一个使用Ant进行自动化构建的实战案例,包括编译、测试、文档生成等环节,并利用Hibernate工具实现数据库自动生成。

在工程目录下创建libs/hibernate/ ,放入

hibernate-tools-3.2.0.ga.jar

jtidy-4aug2000r7-dev.jar

 

build.properties

project.name=sw
project.version=1.0
basedir=.

build.dir =${basedir}/build
web.dir = ${basedir}/WebRoot
lib.dir = ${basedir}/libs
sql.dir = ${basedir}/sql
config.dir=${basedir}/config

main.dir = ${basedir}/src
test.dir = ${basedir}/test

classes.dir = ${build.dir}/main/classes
test.classes.dir = ${build.dir}/test/classes

web.inf.dir = ${web.dir}/WEB-INF
web.lib.dir = ${web.inf.dir}/lib

database.dir = ${build.dir}/database
database.file = ${database.dir}/data
database.alias = sw
database.port= 3306

 

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== 
     2008-1-20                                                      

     friends   
     description
                   
     zhengfuchun                                                              
     ====================================================================== -->
<project name="sw" default="help">
	<description>
            description
    </description>
	<property file="build.properties" />


	<path id="classpath.compile">
		<fileset dir="${web.lib.dir}">
			<include name="*.jar" />
		</fileset>

	</path>

	<path id="classpath.compile.test">
		<fileset dir="${web.lib.dir}/">
			<include name="*.jar" />
		</fileset>
		<fileset dir="${lib.dir}/test">
			<include name="*.jar" />
		</fileset>
		<fileset dir="${lib.dir}/jetty">
			<include name="*.jar" />
		</fileset>
		<pathelement path="${classes.dir}" />
	</path>


	<path id="classpath.junit.test">
		<path refid="classpath.compile.test" />
		<pathelement path="${test.classes.dir}" />
	</path>

	<path id="classpath.hibernate">
		<pathelement path="${classes.dir}" />
		<fileset dir="${web.lib.dir}/">
			<include name="*.jar" />
		</fileset>
		<fileset dir="${lib.dir}/hibernate">
			<include name="*.jar" />
		</fileset>
	</path>


	<!-- ================================= 
          target: compile              
         ================================= -->
	<target name="compile" description="description">
		<deltree dir="${classes.dir}" />
		<mkdir dir="${classes.dir}" />
		<javac srcdir="${main.dir}"
		       memoryinitialsize="32m"
		       memorymaximumsize="128m"
		       verbose="true"
		       encoding="UTF-8"
		       destdir="${classes.dir}"
		       source="1.6"
		       fork="true"
		       classpathref="classpath.compile"
		       debug="on" />
		<mkdir dir="${classes.dir}/META-INF"/>
		<copydir dest="${classes.dir}/META-INF" src="${main.dir}/META-INF" />
	</target>


	<!-- ================================= 
          target: compile-test              
         ================================= -->
	<target name="compile-test" description="description">
		<deltree dir="${test.classes.dir}" />
		<mkdir dir="${test.classes.dir}" />
		<javac srcdir="${test.dir}"
		       fork="true"
		       verbose="true"
		       encoding="UTF-8"
		       destdir="${test.classes.dir}"
		       classpathref="classpath.compile.test"
		       debug="on" />
	</target>


	<!-- ================================= 
          target: hibernate-dbexport              
         ================================= -->
	<taskdef name="hibernatetool"
	         classname="org.hibernate.tool.ant.HibernateToolTask"
	         classpathref="classpath.hibernate" />
	<!-- ================================= 
          target: generate-db              
         ================================= -->
	<target name="generate-db" depends="compile" description="description">
		<deltree dir="${build.dir}/generated/sql" />
		<mkdir dir="${build.dir}/generated/sql" />

		<hibernatetool>
			<jpaconfiguration persistenceunit="ApplicationEntityManager"
			                  propertyfile="${web.inf.dir}/config/jdbc.properties" />
			<classpath>
				<path location="${classes.dir}" />
			</classpath>
			<hbm2ddl destdir="${build.dir}/generated/sql"
			         outputfilename="mysql.ddl"
			         delimiter=";"
			         format="true"
			         haltonerror="true"
			         drop="true"
			         export="true" />
		</hibernatetool>

	</target>



	<!-- ================================= 
          target: junit-test              
         ================================= -->
	<target name="junit-test" description="description">
		<deltree dir="${build.dir}/junit" />
		<mkdir dir="${build.dir}/junit" />
		<junit printsummary="yes">
			<!-- 需要的classpath -->
			<classpath refid="classpath.junit.test" />
			<batchtest todir="${build.dir}/junit">
				<!-- 单元测试文件为所有src目录下的*Test.java文件 -->
				<fileset dir="${test.src.dir}">
					<include name="**/*Test.java" />
				</fileset>
				<!-- 生成格式为xml,也可以用plain或者brief -->
				<!-- 为什么生成xml,是为了下一步做report用 -->
				<formatter type="xml" />
			</batchtest>
		</junit>
		<!-- 对xml文件生成相应的html文件在reports目录下 -->
		<!-- 如果指定于web可访问的目录,就可以使整个项目组看到单元测试情况 -->
		<mkdir dir="${build.dir}/junit/reports" />
		<junitreport todir="${build.dir}/junit/reports">
			<fileset dir="${build.dir}/junit">
				<include name="TEST-*.xml" />
			</fileset>
			<!-- 带有框架,可以用noframes选不带框架 -->
			<report format="frames" todir="${build.dir}/junit/reports/html" />
		</junitreport>
	</target>



	<!-- 输出api文档 -->
	<target name="doc" description="create api doc">
		<deltree dir="${api.doc.dir}" />
		<mkdir dir="${api.doc.dir}" />
		<echo>generate api doc</echo>
		<javadoc destdir="${api.doc.dir}"
		         encoding="UTF-8"
		         classpathref="classpath.junit.test"
		         author="true"
		         version="true"
		         use="true"
		         access="private"
		         source="1.6"
		         verbose="true"
		         windowtitle="MyApp_API">
			<packageset dir="${src.dir}" defaultexcludes="yes">
				<exclude name="com/junit/**" />
			</packageset>
			<doctitle>
				MyApp.cn</doctitle>
			<bottom>All Rights Reserved.</bottom>
		</javadoc>
	</target>

	<!-- ================================= 
          target: jar              
         ================================= -->
	<target name="jar"
	        depends="compile"
	        description="generate jar for all java classes">
		<deltree dir="${build.dir}/bin" />
		<mkdir dir="${build.dir}/bin" />
		<jar destfile="${build.dir}/bin/${project.name}-${project.version}.jar"
		     basedir="${classes.dir}"
		     whenempty="create"
		     encoding="UTF-8" />

	</target>

	<!-- ================================= 
          target: war              
         ================================= -->
	<target name="war" depends="jar" description="generate war">
		<copydir dest="${build.dir}/web" src="${web.dir}" />
		<copyfile dest="${build.dir}/web/WEB-INF/lib/${project.name}-${project.version}.jar"
		          src="${build.dir}/bin/${project.name}-${project.version}.jar" />
		<war destfile="${build.dir}/bin/${project.name}-${project.version}.war"
		     encoding="UTF-8"
		     basedir="${build.dir}/web"
		     webxml="${build.dir}/web/WEB-INF/web.xml">
		</war>

	</target>


	<!-- ================================= 
          target: help              
         ================================= -->
	<target name="help" description="display help message">
		<echo>******************************************************</echo>
		<echo>compile 				--compile all java source 		</echo>
		<echo>compile-test 			--compile all java test source 	</echo>
		<echo>jar 				--package all classes to a jar file	</echo>
		<echo>war 				--package all web resources to a war file</echo>
		<echo>doc 				--generate all java api doc 	</echo>
		<echo>generate-db 			--generate dababase 	</echo>
		<echo>junit-test 				--run junit test and generate test reports</echo>
		<echo>help 				--display help message</echo>
		<echo>******************************************************</echo>


	</target>



</project>

 

启动mysql

 

执行ant

 



 

数据库将自动生成



 

提供了基于BP(Back Propagation)神经网络结合PID(比例-积分-微分)控制策略的Simulink仿真模型。该模型旨在实现对杨艺所著论文《基于S函数的BP神经网络PID控制器及Simulink仿真》中的理论进行实践验证。在Matlab 2016b环境下开发,经过测试,确保能够正常运行,适合学习和研究神经网络在控制系统中的应用。 特点 集成BP神经网络:模型中集成了BP神经网络用于提升PID控制器的性能,使之能更好地适应复杂控制环境。 PID控制优化:利用神经网络的自学习能力,对传统的PID控制算法进行了智能调整,提高控制精度和稳定性。 S函数应用:展示了如何在Simulink中通过S函数嵌入MATLAB代码,实现BP神经网络的定制化逻辑。 兼容性说明:虽然开发于Matlab 2016b,但理论上兼容后续版本,可能会需要调整少量配置以适配不同版本的Matlab。 使用指南 环境要求:确保你的电脑上安装有Matlab 2016b或更高版本。 模型加载: 下载本仓库到本地。 在Matlab中打开.slx文件。 运行仿真: 调整模型参数前,请先熟悉各模块功能和输入输出设置。 运行整个模型,观察控制效果。 参数调整: 用户可以自由调节神经网络的层数、节点数以及PID控制器的参数,探索不同的控制性能。 学习和修改: 通过阅读模型中的注释和查阅相关文献,加深对BP神经网络与PID控制结合的理解。 如需修改S函数内的MATLAB代码,建议有一定的MATLAB编程基础。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值