一次web发布过程的相关配置

发布环境: 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 


二.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> 

ps:如果要支持reloadble,代码为:
<Context path="/cpms" docBase="cpms"   debug="0" privileged="true" reloadable="false">



记得把jdbc驱动拷贝到Tomcat的common\lib下

优化jvm参数
修改Tomcat的bin目录下的catalina.bat文件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>

四.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>

五.这个其实不是配置,应该算是一项优化方案,即jsp预编译
jsp预编译有2个好处

    1提高jsp响应速度,因为jsp全部预先编译成class了,少了中间的环节
    2增强jsp安全性,你的jsp源码可以全部删除,只提供一个YourJsps.jar包到lib就可以了
在weblogic里预编译非常方便,可以在console里配置通过开关配置这个参数,但是Tomcat就没有这个好事了,不过我们可以手工完成,我找了下资料,在ant里配置如下:
<!-- =================================================================== -->
    <!--            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>

你可能感兴趣的:(tomcat,Hibernate,Web,struts,配置管理)