1. I use the myeclipse2014 version, the other 8.5 or more of the same generally slightly different
2.myeclipse use the installed JDK1.7,TOMCAT6. Make sure the myeclipse is working properly before building the frame
3. I am slightly lazy, almost all use MyEclipse features, various files automatically generated. Want to manually write a durable layer method, one day can only write a lot, tired people do not say, the boss every day shouting efficiency is too low, really helpless, had to use tools to achieve, although shielding the technical details and principle is not my intention, but can be completed a long time work, or feel full of accomplishment.
Enter the specific implementation section below:
Start with a clear goal: build Web Apps with SSH
1. Create a new Web project named CCCC, with CCCC as the project name.
2. The creation end is a normal Web project, which I used to implement with the MVC pattern, jsp+servlet+hibernate. Now is the struts2 instead of jsp+servlet,hibernate or hibernate,spring to host struts2 and hibernate.
3. Now import the jar packages required for SSH. A single frame can be a single framework to import the jar package required, basically the same, but now directly from the myeclipse inside the import, do not download it manually (because the download has been notified by the company, brooding, mood uncomfortable, in this vent). Right-click on the project-"myeclipse--" Project Facets[capabilities] (this place myeclipse10 not do it, but now it feels better)-"Install Apatch struts2.x Facet. Import the core package by default when imported, and later use of the other re-import on the line, here first to build up the framework. The same steps are imported into hibernate (you need to configure the database, this is similar to configuring JDBC parameters, note manual Download database connection files into the Lib directory) and spring, but also import the default core package. The effect after import is that there are three more folders in the Web project: Struts2.1 library,hibernate4.1.4 library,spring 3.1.1 Libraries three library folders. Tap to see what package you just imported.
Since hibernate (down to the default h) and struts2 (S2 down by default) contain Antlr-x.x.x.jar, mine is the one that removes the lower version of S2. The actual operation will encounter the inability to cancel the core package in the jar package, in fact, tick an option can be arbitrarily deleted. What to do: Project Right-click-"Build path---" Config Build path (is not very familiar with the interface)--"liberies tab-" Double left click, will pop up a window, here to check. --"(gray display can not be modified, it doesn't matter, see below there is an enable project specific Advanced Configuration check box, check and then you can check the deletion of the selected). The purpose of this pruning is to remove the lower version of the conflicting jar package. Similarly, you can compare the three library folders you just imported, see if there are different versions of the same name or the same version number of the same package, some words to remove duplicates.
To the end of this import jar package. Whether there are three profiles: Applicationcontext.xml,hibernate.cfg.xml,struts.xml. This is the most basic configuration file. To the Web-inf directory, look at Web. XML, the Struts.xml filter has been automatically configured in.
<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>
And the same with spring's
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
Where is hibernate configured? See if Application.xml has automatic configuration, no words to configure
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method= "Close" >
<property name= "Driverclass" value= "Com.mysql.jdbc.Driver"/>
<property name= "Jdbcurl"
Value= "Jdbc:mysql://localhost:3306/cccc?characterencoding=utf-8"/>
<property name= "User" value= "root"/>
<property name= "Password" value= "123456"/>
</bean>
<bean id= "Sessionfactory"
class= "Org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
<property name= "Configlocation"
Value= "Classpath:hibernate.cfg.xml" >
</property>
<property name= "DataSource" ref= "DataSource"/>
</bean>
This completes the configuration XML file. The rest of the parameters, please configure themselves, within each framework and the configuration of a single frame is similar.
MyEclipse building an SSH framework