开发工具: IntelliJ IDEA 6.0 4
SpringSide Version: Springside-2.0-RC1
JDK Version: JDK1.5
Tomcat version: Apache-tomcat-5.5.23
一:修改SS2的数据源
由于ss2默认的是hsqldb,而我用mssql,mysql,所以修改数据库连接,修改src/resources/config/jdbc.properties
|
#jdbc.driverClassName=org.hsqldb.jdbcDriver #jdbc.url=jdbc:hsqldb:res:/hsqldb/helloworld #jdbc.username=sa #jdbc.password=![]() # Mircosoft SQL Server 2000 Driver #jdbc.driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver #jdbc.url=jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=weihandb;SelectMethod=cursor #jdbc.username=sa #jdbc.password=sa![]() # JDBC for MySQL Driver #jdbc.driverClassName=org.gjt.mm.mysql.Driver #jdbc.url=jdbc:mysql://localhost/softforum?user=soft
&password
=1234
&useUnicode
=true
&characterEncoding
=utf-8 #jdbc.username=sa #jdbc.password=sa![]() # Use Jtds for driver Mircosoft SQL 2000 jdbc.driverClassName=net.sourceforge.jtds.jdbc.Driver jdbc.url=jdbc:jtds:sqlserver://localhost:1433;DatabaseName=weihandb;autoReconnect=true jdbc.username=sa jdbc.password=sa
|
然后Copy相应的Mysql 或者MSSQL提供的JDBC驱动(jar包)到wabapp/WEB-INF/lib下面
Note:
如果是用MSSQL的朋友请注意jdbc的驱动不要用ms自己提供的3个驱动包(msbase.jar/mssqlserver.jar/msutil.jar),我在开发中就遇到查找字段顺序的问题 Microsoft 的 SQL 2000的JDBC的BUG其实很多人都应该知道,那就是在包含了blob或clob类型的字段,也就是Image和Text类型。必须按照select顺序查询,且不支持重复查询。 后来Google了一下,发现面对这种情况,只有更换驱动了,可以使用jtds,一个开源的驱动包,但听说即使微软最新的FOR SQL
二. 使用Ant辅助开发
在你project下面新建一个build.xml文件(可以随便放在哪个目录),然后copy下面那段ant代码到你build.xml。然后修改tomcat的目录和你classes文件的目录,可以参照我的配置。
有些时候在开发的不需要重新启动Tomcat来调试程序,用ant可以把相应的文件copy到应用服务器上,copy资源文件的时候还可以自动完成中文转ASCII码操作,更好的做法是可以用Ant来为项目做自动化构建,测试,部署等操作。我这里没有实现,大家有时间可以自己写上。我这里只是实现copy资源文件、class文件、测试文件,web文件到部署发布的目录下。推荐大家看《用Ant自动化构建、部署》那本书。里面讲得很详细。
|
<?
xml version="1.0" encoding="UTF-8"
?>
<
project
name
="smarthings"
default
="usage"
>
<
property
name
="tomcat_path"
value
="F:Developer ToolsTomcatapache-tomcat-5.5.23apache-tomcat-5.5.23"
/>
<
property
name
="example_path"
value
="F:SonicWorkSpaceSpringside-2.0-RC1exampleshelloworldwebappWEB-INFclasses"
/>
<
property
name
="class_path"
value
="${tomcat_path}/webapps/helloworld/WEB-INF/classes"
/>
![]()
<
property
name
="deploy_path"
value
="${tomcat_path}/webapps"
/>
<
property
name
="build_path"
value
="src"
/>
<
property
name
="src_path"
value
="src"
/>
<
property
name
="bin_path"
value
="bin"
/>
<
property
name
="jar"
value
="SmarThingWeb"
/>
<!--
Jar package name
-->
![]()
<
property
name
="springside.dir"
value
="../../"
/>
<!--
引入属性文件
-->
<
property
file
="bin/build.properties"
/>
<
property
file
="bin/build_user.properties"
/>
<!--
引入springside build_base.xml模板
-->
<
import
file
="bin/build_main.xml"
/>
![]()
<!--
复制资源配置文件到发布的目录下 Copy any resource or configuration files
-->
<
target
name
="copy-resources-file"
description
="复制 *.properties 和 *.xml 文件到发布目录下 Copy .properties and .xml files from source directory"
>
<
copy
todir
="${tomcat_path}/webapps/helloworld/WEB-INF/classes"
includeEmptyDirs
="no"
>
<!--
Copy到哪个目录
-->
<
fileset
dir
="src/resources"
>
<!--
要Copy文件的目录
-->
<
exclude
name
="i18n/messages_zh_CN.properties"
/>
<!--
exclude 不包括哪些文件
-->
<
include
name
="**/*.properties"
/>
<!--
包括那些类型的文件
-->
<
include
name
="**/*.xml"
/>
<
include
name
="**/*.script"
/>
</
fileset
>
<!--
<filterset refid="variables.to.replace"/> 为以后自动化构建预留
-->
</
copy
>
<!--
中文转ASCII码操作
-->
<
native2ascii
src
="src/resources/i18n/cn"
dest
="${class_path}/i18n"
encoding
="UTF-8"
>
<
include
name
="messages_zh_CN.properties"
/>
</
native2ascii
>
</
target
>
![]()
<!--
===================================================================
-->
<!--
拷贝JSP文件到发布服务器上
-->
<!--
===================================================================
-->
<
target
name
="copy-web-files"
description
="Copy web files"
>
<
echo
message
="正在拷贝JSP文件 Copying static files"
/>
<!--
Remove the copy block below if you're not displaying version/copyright in the footer
-->
<
copy
todir
="${deploy_path}/helloworld/"
>
<
fileset
dir
="webapp"
includes
="**/*.jsp"
/>
</
copy
>
</
target
>
![]()
<!--
===================================================================
-->
<!--
拷贝class文件到 发布服务器的WEB-INF/class下
-->
<!--
===================================================================
-->
<
target
name
="copy-class-files"
description
="Copy class file under bin fold "
>
<
echo
message
="正在拷贝Class文件 Copying class files"
/>
<
copy
todir
="${class_path}"
>
<
fileset
dir
="bin/class"
includes
="**/*.class"
/>
</
copy
>
</
target
>
![]()
<!--
===================================================================
-->
<!--
拷贝test文件到 发布服务器的WEB-INF/class下
-->
<!--
===================================================================
-->
<
target
name
="copy-test-files"
description
="Copy the test class file"
>
<
echo
message
="正在拷贝测试文件 Copying test class files"
/>
<
copy
todir
="${class_path}"
>
<
fileset
dir
="bin/test"
includes
="**/*.class"
/>
</
copy
>
</
target
>
</
project
>
|
三.web.xml配置
<!--
Struts Action Mapping
-->
<
servlet
>
<
servlet-name
>
action
</
servlet-name
>
<
servlet-class
>
org.apache.struts.action.ActionServlet
</
servlet-class
>
<
init-param
>
<
param-name
>
config
</
param-name
>
<
param-value
>
/WEB-INF/struts-config.xml, /WEB-INF/config/struts-config-project.xml
</
param-value
>
</
init-param
>
<
load-on-startup
>
1
</
load-on-startup
>
</
servlet
>
|
为你的项目多配置一个struts配置文件
四. 修改Tomcat的catalina.bat(tomcat_path/bin/catalina.bat)
由于我在开发过程中遇到OutOfMemoryError: PermGen space,所以我加大了初始化内存大小。可以根据自己内存大小适当配置,我内存是2G,但不是用来做服务器,所以我配为128,256,如果是服务器的话可以为JAVA_OPTS="-server -XX:PermSize=512M -XX:MaxPermSize=512m或者更大。修改后感觉从海南马自达升级到宝马SUV的感觉,听说互联星空就是用tomcat做服务器的。每天百万的访问量都很稳定。
| 在“echo Using CATALINA_BASE: %CATALINA_BASE%”下面添加 rem ---- Add by sonic ------ JAVA_OPTS="-server -XX:PermSize=128M -XX:MaxPermSize=256m |
其他
Intellij IDEA配置,要把file encode ,properties file配置为 "UTF-8" ,SpringSide中中文国际化做的非常到位,基本不用修改什么东西了,如果用MySQL可能数据库方面要注意一下,还有就是一开始用IntelliJ IDEA打开工程的时候,提示dbunit没有配置,大家可以自己配置吧。我看到好多人一直在用Eclipse。其实上面说的和开发工具无关,Intellij这个工具我也是第一次用,开始是有点不习惯,不过越用越爽.很方便.

本文介绍如何在SpringSide 2项目中配置MSSQL和MySQL数据库,并使用Ant进行辅助开发,包括资源文件复制、中文转ASCII码操作及自动化构建流程。
1万+

被折叠的 条评论
为什么被折叠?



