开发一个JAVA版本的博客系统 -- Fuseblog 的计划 1

来源:互联网 发布:淘宝推荐的店铺怎样找 编辑:程序博客网 时间:2024/04/29 19:28
 logo 设计不会,就这样先凑合了
写道
Fuseblog预备开发带在线SHOP功能的个人博客系统.仿照Appfuse
提供一个完全自动化的ant构建脚本.在线SHOP的数据库建模图例已经
在博客中贴出.感兴趣的和我一起搭建,嘻嘻


文档博客地址: http://forum.sinomagazine.com

开发环境:
Jcreator-4.5 JDK-1.5 Ant-1.6.1 MYSQL-5 Tomcat-5.5
Spring-2.5.6 Ibatis-2.3.4

问题事项:
1.在windows系统中,命令行中执行ant命令时,当指定的
构建脚本文件中包含中文字符,而构建脚本文件的编码是UTF-8时将会
Invalid byte 1 of 1-byte UTF-8 sequence. 的错误.这个问题尚未
知解决,故先采用GBK的编码.
2.在Jcreator中创建的项目,不支持UTF-8编码,缺省GBK.

 

以下先列出初步的的ant构建文件的代码: build.xml

<?xml version="1.0" encoding="GBK"?><project name="fuseblog" default="all" basedir=".">    <description>    <![CDATA[    Fuseblog预备开发带在线SHOP功能的个人博客系统.仿照Appfuse    提供一个完全自动化的ant构建脚本.在线SHOP的数据库建模图例已经    在博客中贴出.感兴趣的和我一起搭建,嘻嘻        文档博客地址: http://forum.sinomagazine.com        开发环境:    Jcreator-4.5 JDK-1.5 Ant-1.7.0 MYSQL-5 Tomcat-5.5    Spring-2.5.6 Ibatis-2.3.4            问题事项:     1.在windows系统中,命令行中执行ant命令时,当指定的    构建脚本文件中包含中文字符,而构建脚本文件的编码是UTF-8时将会    Invalid byte 1 of 1-byte UTF-8 sequence. 的错误.这个问题尚未    知解决,故先采用GBK的编码.    2.在Jcreator中创建的项目,不支持UTF-8编码,缺省GBK.    ]]>    </description>        <target name="all">        <!-- TODO define script. See http://ant.apache.org/ -->    </target>        <!--<![CDATA[    定义项目使用的目录结构用到的属性    ]]>-->        <property name="src.dir" value="src"/>    <property name="lib.dir" value="lib"/>    <property name="test.dir" value="test"/>    <property name="war.dir" value="war"/>    <property name="class.dir" value="${war.dir}/classes"/>    <property name="test.class.dir" value="${test.dir}/classes" />            <!--<![CDATA[ 组动作说明        动作: 定义项目中的classpath环境变量    ]]>-->        <path id="fuseblog.class.path">    <fileset dir="${lib.dir}/spring-2.5.6/dist/modules">        <include name="*.jar"/>        <exclude name="spring-webmvc-struts.jar"/>        <exclude name="spring-test.jar"/>    </fileset>        <pathelement location="${lib.dir}/log4j-1.2.15/log4j.jar" />    <pathelement location="${lib.dir}/j2ee/servlet-api.jar" />    <dirset dir="${basedir}" />    <dirset dir="${class.dir}" />        </path>        <path id="junit.class.path">    <path refid="fuseblog.class.path" />    <pathelement location="${lib.dir}/junit-3.8.2/junit.jar" />    </path>        <!--<![CDATA[    动作: 初始化项目构建过程所需的资源    ]]>-->    <target name="init">    <mkdir dir="${class.dir}"></mkdir>    <mkdir dir="${test.class.dir}"></mkdir>    </target>                <!--<![CDATA[    动作: 编译项目中的源文件    ]]>-->    <target name="compile" depends="init">    <javac srcdir="${src.dir}" destdir="${class.dir}" />        </target>        <!--<![CDATA[    动作: 编译用于单元测试的源文件    ]]>-->     <target name="compile.test" depends="init">    <javac srcdir="${test.dir}" destdir="${test.class.dir}"    classpathref="junit.class.path">    </javac>        </target>      <!--<![CDATA[    动作: 清除构建的资源    ]]>-->    <target name="clean">    <deltree dir="${class.dir}" />    <deltree dir="${test.class.dir}" />     </target>            <!--<![CDATA[    动作: 运行项目    ]]>-->    <target name="run">    <java classname="com.sinomagazine.fuseblog.FuseBlog"     classpath="${class.dir}" fork="yes"></java>    </target>            <!--<![CDATA[    动作: 运行项目的单元测试代码    注明: 这个标签刚刚学习,很生疏,呵呵    ]]>-->    <target name="test" depends="compile.test,compile">    <junit printsummary="withOutAndErr"     haltonfailure="no" haltonerror="no" fork="yes">        <classpath refid="junit.class.path" />    <formatter type="xml" usefile="true" />    <batchtest todir="${test.dir}">    <fileset dir="${test.class.dir}">            <include name="*Test.*"/>    </fileset>    </batchtest>        </junit>    </target>            <!--<![CDATA[    动作: 运行ant脚本时出现5秒的logo提示    ]]>-->    <splash imageurl=""           useproxy="true"           showduration="2000"/>    </project>

 

由于在其中 使用了 <junit>标签,所以需要将junit.jar拷贝到ant的lib目录下...

 

 

FuseBlog.java

package com.sinomagazine.fuseblog;public class FuseBlog {public static void main(String[] args) {System.out.println ("Fuseblog 应用程序");}@Overridepublic String toString(){return "Fuseblog 应用程序" ;}}

 

test\FuseBlogTest.java

import junit.framework.TestCase;import com.sinomagazine.fuseblog.FuseBlog ;public class FuseBlogTest extends TestCase {private FuseBlog fuseblog ;@Overridepublic void setUp(){this.fuseblog = new FuseBlog();}public void testToString(){assertNull(this.fuseblog.toString());assertNotNull(this.fuseblog.toString());assertEquals(this.fuseblog.toString(),"Fuseblog 应用程序");}}

 

在此搭建出了项目的初步结构代码,并且集成了自动化的单元测试功能...

 

然后进入命令提示符,切换到当前项目的文件夹,输入:

写道
ant test

将会显示如下图所示内容:

 

原创粉丝点击