手动搭建SSH项目
?本文主要讲述:按照我们公司demo的相似手动搭建SSH项目,以及使用ant进行编译。
本文主要是为我做一个思路的整理。如果你只拷贝一下下面代码能跑起来,估计不可能。
?
一、创建MyEclipse创建java工程MySSH
1、寻找一个web项目,创建文件夹和一些web文件
其中java和resources文件夹分别存放源文件和配置文件。
必须通过一下方式建立,否则文件夹会以包名的方式存在。
其中下面Default output folder目录我修改了。
这个目录为编译后的class文件和xml文件目录。
二、加包
这个是我用的包。我是从其他项目拷贝。
三:struts
web.xml
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>?
struts.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts></struts>
?
四、spring+hibernate
?? 1、web.xml,加入spring的控制
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xmlclasspath:database.xml</param-value></context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>?
?? 2、applicationContext.xml
<bean id="lobHandler" lazy-init="true" /> <context:component-scan base-package="com"/><!-- this is just use in the ENV of integration testing <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/snsDS" />--> <bean id="jdbcTemplate" p:dataSource-ref="dataSource"/><bean id="transactionManager" p:dataSource-ref="dataSource"/><tx:annotation-driven transaction-manager="transactionManager"/> <tx:annotation-driven proxy-target-/>
?
?? 3、database.xml
<bean id="dataSource" dependency-check="default"> <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"> </property> <property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl"> </property> <property name="user" value="kevin"></property> <property name="password" value="zwk"></property> </bean> <bean id="sessionFactory" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.connection.pool.size">10</prop> <prop key="hibernate.show_sql">true</prop> <prop key="jdbc.fetch_size">100</prop> <prop key="jdbc.batch_size">50</prop> <prop key="jdbc.use_scrollable_resultset">false</prop> <prop key="hibernate.hbm2ddl.auto">none</prop> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect </prop> </props> </property> <!-- 需要加载的Hibernate实体类(不需要hbm.xml了) --><property name="packagesToScan" value="com.**.entity"/> </bean> <bean id="baseDAO" /> </property> </bean>
?
五、tomcat conf.xml配置
<Host name="localhost" appBase="" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="D:\Project\workspace_MyEclipse\MySSH\WebContent"debug="0" reloadable="true" />?
六、ant
build.xml
<?xml version="1.0" encoding="UTF-8"?><project name="MySSH" default="dist" basedir="."> <!-- set global properties for this build --> <property name="src" location="src/main/java/"/> <property name="resources" location="src/main/resources/"/> <property name="build" location="WebContent/WEB-INF/classes/"/> <property name="dist" location="WebContent/WEB-INF/lib/"/> <!--<property name="serverconfig" location="../../serverconfig/"/>--> <path id="classpath"><fileset dir="${dist}" id="jslibs"><include name="**/*.jar" /></fileset><dirset dir="${build}"></dirset> </path> <target name="init"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <mkdir dir="${build}"/> <mkdir dir="${dist}"/> </target> <target name="compile" depends="init" description="compile the source " > <javac srcdir="${src}" debug="on" destdir="${build}" fork="true" classpathref="classpath" encoding="utf-8" memoryMaximumSize ="500M" compiler="javac1.5"><compilerarg value="-Xlint:unchecked"/> </javac><copy todir="${build}" overwrite="true"><fileset dir="${src}"><exclude name="**/*.java"/></fileset><fileset dir="${resources}"><exclude name="**/*.java"/></fileset></copy></target> <target name="dist" depends="compile" description="generate the distribution" > </target></project>?
?
?
?
?
?
?
?
?