一次web发布过程的相关配置
keyword: 配置 Tomcat配置 MySql配置 server.conf my.ini 启动参数 虚拟机参数 jsp预编译
Author: Alex
发布环境: Tomcat5 + MySql4 +Hibernate + Win2003
一.MySql配置文件
my.ini文件配置
二.Tomcat配置文件
相关配置如下:
ps:如果要支持reloadble,代码为:
<Context path="/cpms" docBase="cpms" debug="0" privileged="true" reloadable="false">
记得把jdbc驱动拷贝到Tomcat的common\lib下
注:如果你的 Tomcat是通过service方式启动的这个设置不起作用,所以你最好通过startup.bat方式来启动,service 是直接调用Tomcat.exe,所以不知道怎么设置参数,我试了一下在服务里的"启动参数"里加入
-Xms512m -Xmx512m好像不起作用.知道的兄弟补充下啊
好了,启动你的Tomcat吧,查看资源管理器,看内存是否已经被Tomcat占用了512M
三.web.xml配置
主要涉及数据源,servlet,tld映射
web.xml配置如下:
四.hibernate配置文件,hibernate.cfg.xml
五.这个其实不是配置,应该算是一项优化方案,即jsp预编译
jsp预编译有2个好处
有一点不是很方便,就是要手工把生成的webJSP.xml的内容拷贝到web.xml中,应该有更方便的办法,比如
在web.xml中引入这个文件.不过我不知道怎么引入.知道的一定要告诉我啊 :)
我试了下,执行jsp2java没有问题,不过java2class则报错,错误如下:
不知道怎么搞的,该提供的类路径全给了,好像是Struts的标签解析的时候出错了,还有什么地方会出问题呢,过段时间再研究这个问题,知道的兄弟也告知下哦 :)
大致就这些了.
后记:java2class报错原因已经找到,是jar文件冲突出错,我用的是servlet2.3.jar,以前不知从哪下的,后来把tomcat目录下的common\lib下的servlet-api.jar做servlet解析就没问题了
Author: Alex
发布环境: Tomcat5 + MySql4 +Hibernate + Win2003
一.MySql配置文件
my.ini文件配置
# The default character set that will be used when a new schema or table is
# created and no character set is defined
####设置字符集,MySql默认为 latin1,如果你的存储出现乱码就改为GBK吧
#default-character-set = latin1
default-character-set = GBK
# The default storage engine that will be used when create new tables when
###建议用INNODB,支持事务
default-storage-engine = INNODB
# created and no character set is defined
####设置字符集,MySql默认为 latin1,如果你的存储出现乱码就改为GBK吧
#default-character-set = latin1
default-character-set = GBK
# The default storage engine that will be used when create new tables when
###建议用INNODB,支持事务
default-storage-engine = INNODB
二.Tomcat配置文件
- server.conf
相关配置如下:
<
Context
path
="/sample"
docBase
="
sample
"
debug
="0"
privileged
="true"
>
< Resource name ="jdbc/ sample " auth ="Container" type ="javax.sql.DataSource" />
< ResourceParams name ="jdbc/ sample " >
< parameter >
< name > username </ name >
< value > sample </ value >
</ parameter >
< parameter >
< name > password </ name >
< value > sample </ value >
</ parameter >
< parameter >
< name > driverClassName </ name >
< value > org.gjt.mm.mysql.Driver </ value >
</ parameter >
< parameter >
< name > url </ name >
< value > jdbc:mysql://localhost/ sample </ value >
</ parameter >
</ ResourceParams >
</ Context >
< Resource name ="jdbc/ sample " auth ="Container" type ="javax.sql.DataSource" />
< ResourceParams name ="jdbc/ sample " >
< parameter >
< name > username </ name >
< value > sample </ value >
</ parameter >
< parameter >
< name > password </ name >
< value > sample </ value >
</ parameter >
< parameter >
< name > driverClassName </ name >
< value > org.gjt.mm.mysql.Driver </ value >
</ parameter >
< parameter >
< name > url </ name >
< value > jdbc:mysql://localhost/ sample </ value >
</ parameter >
</ ResourceParams >
</ Context >
ps:如果要支持reloadble,代码为:
<Context path="/cpms" docBase="cpms" debug="0" privileged="true" reloadable="false">
记得把jdbc驱动拷贝到Tomcat的common\lib下
- 优化jvm参数
set JAVA_OPTS
=
-Xms512m -Xmx512m
注:如果你的 Tomcat是通过service方式启动的这个设置不起作用,所以你最好通过startup.bat方式来启动,service 是直接调用Tomcat.exe,所以不知道怎么设置参数,我试了一下在服务里的"启动参数"里加入
-Xms512m -Xmx512m好像不起作用.知道的兄弟补充下啊
好了,启动你的Tomcat吧,查看资源管理器,看内存是否已经被Tomcat占用了512M
三.web.xml配置
主要涉及数据源,servlet,tld映射
web.xml配置如下:
<?
xml version="1.0" encoding="UTF-8"
?>
<! DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
< web-app >
< display-name > CPMSWeb </ display-name >
< 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 </ param-value >
</ init-param >
< init-param >
< param-name > debug </ param-name >
< param-value > 2 </ param-value >
</ init-param >
< init-param >
< param-name > application </ param-name >
< param-value > ApplicationResources </ param-value >
</ init-param >
< load-on-startup > 2 </ load-on-startup >
</ servlet >
<servlet>
<servlet-name>com.my.DataServlet</servlet-name>
<servlet-class> com.my.DataServlet </servlet-class>
<init-param>
<param-name>license</param-name>
<param-value>/WEB-INF/license.dat</param-value>
</init-param>
<!--为DataServlet提供datasource-->
<init-param>
<param-name>dataSource</param-name>
<param-value>jdbc/report,mysql,GBK</param-value>
</init-param>
<init-param>
<init-param>
<param-name>maxConcurrentForBigReport</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>logConfig</param-name>
<param-value>/WEB-INF/runqianReportLog.properties</param-value>
</init-param>
<init-param>
<param-name>certFile</param-name>
<param-value>C:\Documents and Settings\sjr\.keystore</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<filter>
<filter-name>eXtremeExport</filter-name>
<filter-class>
org.extremecomponents.table.filter.ExportFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>eXtremeExport</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
< taglib >
< taglib-uri > /WEB-INF/struts-bean.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-bean.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-html.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-html.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-logic.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-logic.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-template.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-template.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-tiles.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-tiles.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-nested.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-nested.tld </ taglib-location >
</ taglib >
<!--配置一些定制的配置文件-->
< env-entry >
< env-entry-name > ConfigXmlFilePath </ env-entry-name >
< env-entry-value > C:/config.xml </ env-entry-value >
< env-entry-type > java.lang.String </ env-entry-type >
</ env-entry >
</ web-app >
<! DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
< web-app >
< display-name > CPMSWeb </ display-name >
< 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 </ param-value >
</ init-param >
< init-param >
< param-name > debug </ param-name >
< param-value > 2 </ param-value >
</ init-param >
< init-param >
< param-name > application </ param-name >
< param-value > ApplicationResources </ param-value >
</ init-param >
< load-on-startup > 2 </ load-on-startup >
</ servlet >
<servlet>
<servlet-name>com.my.DataServlet</servlet-name>
<servlet-class> com.my.DataServlet </servlet-class>
<init-param>
<param-name>license</param-name>
<param-value>/WEB-INF/license.dat</param-value>
</init-param>
<!--为DataServlet提供datasource-->
<init-param>
<param-name>dataSource</param-name>
<param-value>jdbc/report,mysql,GBK</param-value>
</init-param>
<init-param>
<init-param>
<param-name>maxConcurrentForBigReport</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>logConfig</param-name>
<param-value>/WEB-INF/runqianReportLog.properties</param-value>
</init-param>
<init-param>
<param-name>certFile</param-name>
<param-value>C:\Documents and Settings\sjr\.keystore</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<filter>
<filter-name>eXtremeExport</filter-name>
<filter-class>
org.extremecomponents.table.filter.ExportFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>eXtremeExport</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
< taglib >
< taglib-uri > /WEB-INF/struts-bean.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-bean.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-html.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-html.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-logic.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-logic.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-template.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-template.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-tiles.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-tiles.tld </ taglib-location >
</ taglib >
< taglib >
< taglib-uri > /WEB-INF/struts-nested.tld </ taglib-uri >
< taglib-location > /WEB-INF/struts-nested.tld </ taglib-location >
</ taglib >
<!--配置一些定制的配置文件-->
< env-entry >
< env-entry-name > ConfigXmlFilePath </ env-entry-name >
< env-entry-value > C:/config.xml </ env-entry-value >
< env-entry-type > java.lang.String </ env-entry-type >
</ env-entry >
</ web-app >
四.hibernate配置文件,hibernate.cfg.xml
<?
xml version="1.0" encoding="utf-8"
?>
<! DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd" >
< hibernate-configuration >
< session-factory >
< property name ="hibernate.connection.provider_class" > net.sf.hibernate.connection.C3P0ConnectionProvider </ property >
< property name ="hibernate.connection.url" > jdbc:mysql://localhost/sample </ property >
< property name ="hibernate.connection.driver_class" > org.gjt.mm.mysql.Driver </ property >
< property name ="hibernate.connection.username" > sample </ property >
< property name ="hibernate.connection.password" >sample </ property >
< property name ="hibernate.use_outer_join" > True </ property >
< property name ="connection.pool_size" > 50 </ property >
< property name ="show_sql" > true </ property >
< property name ="use_outer_join" > true </ property >
< property name ="jdbc.fetch_size" > 50 </ property >
< property name ="jdbc.batch_size" > 50 </ property >
< property name ="dialect" > net.sf.hibernate.dialect.MySQLDialect </ property >
<!--
<property name="hibernate.dbcp.maxActive">50</property>
<property name="hibernate.dbcp.whenExhaustedAction">1</property>
<property name="hibernate.dbcp.maxWait">120000</property>
<property name="hibernate.dbcp.maxIdle">30</property>
-->
<!-- configuration pool via c3p0 -->
< property name ="c3p0.acquire_increment" > 1 </ property >
< property name ="c3p0.idle_test_period" > 100 </ property > <!-- seconds -->
< property name ="c3p0.max_size" > 100 </ property >
< property name ="c3p0.max_statements" > 0 </ property >
< property name ="c3p0.timeout" > 100 </ property > <!-- seconds -->
<!-- DEPRECATED very expensive property name="c3p0.validate> -->
< property name ="cache.provider_class" > net.sf.hibernate.cache.HashtableCacheProvider </ property >
< property name ="hibernate.transaction.factory_class" > net.sf.hibernate.transaction.JDBCTransactionFactory </ property >
< property name ="hibernate.cglib.use_reflection_optimizer" > false </ property >
< mapping resource ="conf/mapping/Sample.hbm.xml" />
</ session-factory >
</ hibernate-configuration >
<! DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd" >
< hibernate-configuration >
< session-factory >
< property name ="hibernate.connection.provider_class" > net.sf.hibernate.connection.C3P0ConnectionProvider </ property >
< property name ="hibernate.connection.url" > jdbc:mysql://localhost/sample </ property >
< property name ="hibernate.connection.driver_class" > org.gjt.mm.mysql.Driver </ property >
< property name ="hibernate.connection.username" > sample </ property >
< property name ="hibernate.connection.password" >sample </ property >
< property name ="hibernate.use_outer_join" > True </ property >
< property name ="connection.pool_size" > 50 </ property >
< property name ="show_sql" > true </ property >
< property name ="use_outer_join" > true </ property >
< property name ="jdbc.fetch_size" > 50 </ property >
< property name ="jdbc.batch_size" > 50 </ property >
< property name ="dialect" > net.sf.hibernate.dialect.MySQLDialect </ property >
<!--
<property name="hibernate.dbcp.maxActive">50</property>
<property name="hibernate.dbcp.whenExhaustedAction">1</property>
<property name="hibernate.dbcp.maxWait">120000</property>
<property name="hibernate.dbcp.maxIdle">30</property>
-->
<!-- configuration pool via c3p0 -->
< property name ="c3p0.acquire_increment" > 1 </ property >
< property name ="c3p0.idle_test_period" > 100 </ property > <!-- seconds -->
< property name ="c3p0.max_size" > 100 </ property >
< property name ="c3p0.max_statements" > 0 </ property >
< property name ="c3p0.timeout" > 100 </ property > <!-- seconds -->
<!-- DEPRECATED very expensive property name="c3p0.validate> -->
< property name ="cache.provider_class" > net.sf.hibernate.cache.HashtableCacheProvider </ property >
< property name ="hibernate.transaction.factory_class" > net.sf.hibernate.transaction.JDBCTransactionFactory </ property >
< property name ="hibernate.cglib.use_reflection_optimizer" > false </ property >
< mapping resource ="conf/mapping/Sample.hbm.xml" />
</ session-factory >
</ hibernate-configuration >
五.这个其实不是配置,应该算是一项优化方案,即jsp预编译
jsp预编译有2个好处
- 提高jsp响应速度,因为jsp全部预先编译成class了,少了中间的环节
- 增强jsp安全性,你的jsp源码可以全部删除,只提供一个YourJsps.jar包到lib就可以了
<!--
===================================================================
-->
<!-- precompile jsp -->
<!-- =================================================================== -->
< target name ="jsp2java" >
< taskdef classname ="org.apache.jasper.JspC" name ="jsp2java" >
< classpath id ="jsp2java.classpath" >
< fileset dir ="${tomcat.home}/bin" >
< include name ="*.jar" />
</ fileset >
< fileset dir ="${tomcat.home}/server/lib" >
< include name ="*.jar" />
</ fileset >
< fileset dir ="${tomcat.home}/common/lib" >
< include name ="*.jar" />
</ fileset >
</ classpath >
</ taskdef >
< jsp2java classpath ="jsp2java.classpath" javaEncoding ="UTF-8" validateXml ="false" uriroot ="${web.dir}" webXmlFragment ="${web.dir}/WEB-INF/webJSP.xml" outputDir ="${web.dir}/WEB-INF/JspC/src" />
</ target >
< target name ="java2class" >
< mkdir dir ="${web.dir}/WEB-INF/JspC/classes" />
< javac srcdir ="${web.dir}/WEB-INF/JspC/src" destdir ="${web.dir}/WEB-INF/JspC/classes" encoding ="UTF-8" optimize ="off" debug ="on" failonerror ="false" excludes ="**/*.smap" >
< classpath id ="java2class.classpath" >
< pathelement location ="${web.dir}/WEB-INF/classes" />
< fileset dir ="${web.dir}/WEB-INF/lib" >
< include name ="*.jar" />
</ fileset >
< pathelement location ="${tomcat.home}/common/classes" />
< fileset dir ="${tomcat.home}/common/lib" >
< include name ="*.jar" />
</ fileset >
< pathelement location ="${tomcat.home}/shared/classes" />
< fileset dir ="${tomcat.home}/shared/lib" >
< include name ="*.jar" />
</ fileset >
< fileset dir ="${tomcat.home}/bin" >
< include name ="*.jar" />
</ fileset >
</ classpath >
< include name ="**" />
< exclude name ="tags/**" />
</ javac >
</ target >
< target name ="class2jar" >
< jar basedir ="${web.dir}/WEB-INF/JspC/classes" jarfile ="${web.dir}/WEB-INF/lib/${project.name}JSP.jar" />
</ target >
< target name ="clear" >
< delete dir ="${web.dir}/WEB-INF/JspC/classes" />
< delete dir ="${web.dir}/WEB-INF/JspC/src" />
< delete dir ="${web.dir}/WEB-INF/JspC" />
</ target >
<!-- precompile jsp -->
<!-- =================================================================== -->
< target name ="jsp2java" >
< taskdef classname ="org.apache.jasper.JspC" name ="jsp2java" >
< classpath id ="jsp2java.classpath" >
< fileset dir ="${tomcat.home}/bin" >
< include name ="*.jar" />
</ fileset >
< fileset dir ="${tomcat.home}/server/lib" >
< include name ="*.jar" />
</ fileset >
< fileset dir ="${tomcat.home}/common/lib" >
< include name ="*.jar" />
</ fileset >
</ classpath >
</ taskdef >
< jsp2java classpath ="jsp2java.classpath" javaEncoding ="UTF-8" validateXml ="false" uriroot ="${web.dir}" webXmlFragment ="${web.dir}/WEB-INF/webJSP.xml" outputDir ="${web.dir}/WEB-INF/JspC/src" />
</ target >
< target name ="java2class" >
< mkdir dir ="${web.dir}/WEB-INF/JspC/classes" />
< javac srcdir ="${web.dir}/WEB-INF/JspC/src" destdir ="${web.dir}/WEB-INF/JspC/classes" encoding ="UTF-8" optimize ="off" debug ="on" failonerror ="false" excludes ="**/*.smap" >
< classpath id ="java2class.classpath" >
< pathelement location ="${web.dir}/WEB-INF/classes" />
< fileset dir ="${web.dir}/WEB-INF/lib" >
< include name ="*.jar" />
</ fileset >
< pathelement location ="${tomcat.home}/common/classes" />
< fileset dir ="${tomcat.home}/common/lib" >
< include name ="*.jar" />
</ fileset >
< pathelement location ="${tomcat.home}/shared/classes" />
< fileset dir ="${tomcat.home}/shared/lib" >
< include name ="*.jar" />
</ fileset >
< fileset dir ="${tomcat.home}/bin" >
< include name ="*.jar" />
</ fileset >
</ classpath >
< include name ="**" />
< exclude name ="tags/**" />
</ javac >
</ target >
< target name ="class2jar" >
< jar basedir ="${web.dir}/WEB-INF/JspC/classes" jarfile ="${web.dir}/WEB-INF/lib/${project.name}JSP.jar" />
</ target >
< target name ="clear" >
< delete dir ="${web.dir}/WEB-INF/JspC/classes" />
< delete dir ="${web.dir}/WEB-INF/JspC/src" />
< delete dir ="${web.dir}/WEB-INF/JspC" />
</ target >
有一点不是很方便,就是要手工把生成的webJSP.xml的内容拷贝到web.xml中,应该有更方便的办法,比如
在web.xml中引入这个文件.不过我不知道怎么引入.知道的一定要告诉我啊 :)
我试了下,执行jsp2java没有问题,不过java2class则报错,错误如下:
ow_jsp.java:
134
: 无法将 org.apache.jsp.jsp.show_jsp 中的 _jspx_meth_logic_present_2(javax.servlet.js
p.tagext.JspTag , javax.servlet.jsp.PageContext) 应用于 (org.apache.struts.taglib.logic.IterateTag , jav
ax.servlet.jsp.PageContext)
[ javac ] if (_jspx_meth_logic_present_2(_jspx_th_logic_iterate_0 , pageContext))
p.tagext.JspTag , javax.servlet.jsp.PageContext) 应用于 (org.apache.struts.taglib.logic.IterateTag , jav
ax.servlet.jsp.PageContext)
[ javac ] if (_jspx_meth_logic_present_2(_jspx_th_logic_iterate_0 , pageContext))
不知道怎么搞的,该提供的类路径全给了,好像是Struts的标签解析的时候出错了,还有什么地方会出问题呢,过段时间再研究这个问题,知道的兄弟也告知下哦 :)
大致就这些了.
后记:java2class报错原因已经找到,是jar文件冲突出错,我用的是servlet2.3.jar,以前不知从哪下的,后来把tomcat目录下的common\lib下的servlet-api.jar做servlet解析就没问题了