上一章我们已经将maven集成在eclipse中,并且已经配置nexus搭建的私服为maven的仓库。
这一章我们将在eclipse里利用maven建立一个ssh项目。
1、在eclipse中新建一个Dynamic Web Project。如果出现该报错信息,请检查你的tomcat是否有安装,并且是否有配置到eclispe里。
解决办法是,可以直接从界面上找到New Runtime按钮
在弹出的窗口中选择你要添加的服务器类型,笔者这里是选得tomcat6.0
然后下一步,会弹出一个新窗口
Name代表服务器的名字
Tomcate installation directory代表tomcat的安装路径
JRE代表你的java环境,Finish
然后会回到Dynamic Web Project窗口,点击Next,设置项目bulid时(也就是maven install时)的输出路径为target
点击Next,设置Content directory路径为src/main/webapp,然后Finish。这样一个动态web项目就创建好了。
然后设置Java Resources的路径,在左边的项目视图里找到我们刚刚创建的项目,右键->properties,在弹出的窗口里面点击Java Build Path,然后再点击Add Folder…
在main路径下面创建java文件夹,并勾选。
点击ok后,回到刚刚的界面,我会发现,有报错信息。这个时候删除最先的文件夹即可,如图:
然后点击ok,这个时候再次对项目点击右键->Maven->Enable Dependency Management
在弹出的窗口中将Packaging设置成war,然后Finish。
这个时候如果项目报错Java compiler level does not match the version of the installed Java project facet
请按照该贴方法解决:http://cai555.iteye.com/blog/468409
然后就是引入依赖的jar包了。具体在maven中怎么添加jar包,这里就不阐述了,大家可以google一下,非常简单。这里我直接提供pom.xml的内容


setting.xml<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>ssh_demo</groupId> <artifactId>ssh_demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <build> <plugins> <!-- require at least JDK 1.6 to run the build --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <executions> <execution> <id>enforce-java</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireJavaVersion> <version>[1.6,)</version> </requireJavaVersion> </rules> </configuration> </execution> </executions> </plugin> <!-- by default, compile to JDK 1.6 compatibility (individual modules and/or user can override) --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- Test plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> <!--<skip>true</skip> --> </configuration> </plugin> <!-- war plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.0.2</version> <configuration> <!-- <webResources> <webResource> <directory> ${basedir}/src/main/webapp/WEB-INF </directory> <excludes> <exclude>**/content</exclude> </excludes> </webResource> </webResources> --> <webResource> <directory> ${basedir}/src/main/webapp/WEB-INF </directory> <!-- <excludes> <exclude>**/content</exclude> </excludes> --> <includes> <include>**/*.xml</include> </includes> <targetPath>WEB-INF</targetPath> </webResource> <archive> <manifest> <addClasspath>true</addClasspath> </manifest> </archive> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>3.0.3.RELEASE</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-convention-plugin</artifactId> <version>2.2.1</version> <type>jar</type> <scope>compile</scope> <exclusions> <exclusion> <artifactId>tools</artifactId> <groupId>com.sun</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.0.3.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>3.0.3.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.9</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>com.jolbox</groupId> <artifactId>bonecp</artifactId> <version>0.6.7.2</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.1</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.13</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>3.6.0-SNAPSHOT</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>opensymphony</groupId> <artifactId>sitemesh</artifactId> <version>2.4.2</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-sitemesh-plugin</artifactId> <version>2.2.1</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>jexcelapi</groupId> <artifactId>jxl</artifactId> <version>2.6</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>3.0.3.RELEASE</version> <type>jar</type> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <type>jar</type> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.2.1</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.13.0-GA</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>1.6</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.1.0.Beta1</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>commons-configuration</groupId> <artifactId>commons-configuration</artifactId> <version>1.6</version> </dependency> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-json-plugin</artifactId> <version>2.1.8.1</version> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.2.3</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>jaxen</groupId> <artifactId>jaxen</artifactId> <version>1.1.3</version> </dependency> </dependencies> </project>
配置完pom文件后,maven就会自动去从服务器上面下载需要的jar包了,考虑到国内操蛋的网络环境,笔者在这里提供自己的中央仓,里面的jar包都已经基本完善,常用的基本都在。
下载地址:(m2.7z)http://115.com/file/e7xggyua#
最后的效果如图:
配置完jar包后,现在开始配置各种所需要的配置文件。但在这之前,我们先把必须的包建立好,请按下图依次建立好这些包
从上到下他们分别是存放action的包,dao的包,域对象(持久对象)的包,service的包.
然后下面开始配置各种配置文件。
首先是WEB-INF/web.xml


web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>ssh_demo</display-name> <listener><!-- 配置struts监听器 --> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>struts-prepare</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>net.ssh_demo.action</param-value><!-- 配置action路径 --> </init-param> </filter> <filter> <filter-name>struts-execute</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts-prepare</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts-execute</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>/index/index.jsp</welcome-file> </welcome-file-list> <error-page> <error-code>404</error-code> <location>/pages/comm/error_404.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/500error.jsp</location> </error-page> <jsp-config> <jsp-property-group> <description> Special property group for JSP Configuration JSP example. </description> <display-name>JSPConfiguration</display-name> <url-pattern>*.html</url-pattern> <el-ignored>true</el-ignored> <page-encoding>UTF-8</page-encoding> <scripting-invalid>false</scripting-invalid> <include-prelude></include-prelude> <include-coda></include-coda> </jsp-property-group> </jsp-config> </web-app>
然后是WEB-INF/applicationContext.xml


applicationContext.xml<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- 项目路径 --> <context:component-scan base-package="net.ssh_demo" /> <!-- 数据库相关配置 --> <bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1/test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false" /> <property name="username" value="root" /> <property name="password" value="root" /> <property name="idleConnectionTestPeriod" value="60" /> <property name="idleMaxAge" value="240" /> <property name="maxConnectionsPerPartition" value="30" /> <property name="minConnectionsPerPartition" value="10" /> <property name="partitionCount" value="3" /> <property name="acquireIncrement" value="5" /> <property name="statementsCacheSize" value="100" /> <property name="releaseHelperThreads" value="3" /> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy"> <property name="targetDataSource"> <ref local="mainDataSource" /> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.use_sql_comments">true</prop> <prop key="hibernate.jdbc.batch_size">20</prop> <!--<prop key="hibernate.hbm2ddl.auto">create</prop> --> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <property name="packagesToScan" value="net.ssh_demo.domain" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> <!-- aop事务配置 --> <aop:config> <aop:pointcut id="productServiceMethods" expression="execution(* net.ssh_demo.service.imp.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" read-only="false" /> <tx:method name="regist*" propagation="REQUIRED" read-only="false" /> <tx:method name="import*" propagation="REQUIRED" read-only="false" /> <tx:method name="insert*" propagation="REQUIRED" read-only="false" /> <tx:method name="delete*" propagation="REQUIRED" read-only="false" /> <tx:method name="update*" propagation="REQUIRED" read-only="false" /> <tx:method name="edit*" propagation="REQUIRED" read-only="false" /> <tx:method name="remove*" propagation="REQUIRED" read-only="false" /> <tx:method name="add*" propagation="REQUIRED" read-only="false" /> <tx:method name="create*" propagation="REQUIRED" read-only="false" /> <tx:method name="pulish*" propagation="REQUIRED" read-only="false" /> <tx:method name="list*" propagation="SUPPORTS" read-only="true" /> <tx:method name="get*" propagation="SUPPORTS" read-only="true" /> <tx:method name="query*" propagation="SUPPORTS" read-only="true" /> <tx:method name="find*" propagation="SUPPORTS" read-only="true" /> <tx:method name="execute*" propagation="REQUIRED" read-only="false" /> <tx:method name="batch*" propagation="REQUIRED" read-only="false" /> <tx:method name="generate*" propagation="REQUIRED" read-only="false" /> <tx:method name="*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <!-- 配置文件 --> <bean id="propertiesConfiguration" class="org.apache.commons.configuration.PropertiesConfiguration"> <constructor-arg> <value>config.properties</value> </constructor-arg> </bean> </beans>
然后是在src目录下面的数个文件:


struts.properties#log4j.rootCategory=ERROR,stdout,file log4j.rootLogger=ERROR,stdout,file log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n log4j.category.org.springframework.beans.factory=ERROR log4j.category.com.jolbox=ERROR,Console # Stdout log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=[%t] %-5p %c %x - %m%n # file log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=d:\\log.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.MaxFileSize=2048KB log4j.appender.file.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n log4j.appender.file.Threshold = ERROR


log4j.properties# # $Id: default.properties 789467 2009-06-29 22:11:12Z musachy $ # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # ### START SNIPPET: complete_file ### Struts default properties ###(can be overridden by a struts.properties file in the root of the classpath) ### ### Specifies the Configuration used to configure Struts ### one could extend org.apache.struts2.config.Configuration ### to build one's customize way of getting the configurations parameters into Struts # struts.configuration=org.apache.struts2.config.DefaultConfiguration ### This can be used to set your default locale and encoding scheme # struts.locale=en_US struts.i18n.encoding=UTF-8 ### if specified, the default object factory can be overridden here ### Note: short-hand notation is supported in some cases, such as "spring" ### Alternatively, you can provide a com.opensymphony.xwork2.ObjectFactory subclass name here # struts.objectFactory = spring ### specifies the autoWiring logic when using the SpringObjectFactory. ### valid values are: name, type, auto, and constructor (name is the default) struts.objectFactory.spring.autoWire = name ### indicates to the struts-spring integration if Class instances should be cached ### this should, until a future Spring release makes it possible, be left as true ### unless you know exactly what you are doing! ### valid values are: true, false (true is the default) struts.objectFactory.spring.useClassCache = true ### ensures the autowire strategy is always respected. ### valid values are: true, false (false is the default) struts.objectFactory.spring.autoWire.alwaysRespect = false ### if specified, the default object type determiner can be overridden here ### Note: short-hand notation is supported in some cases, such as "tiger" or "notiger" ### Alternatively, you can provide a com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation name here ### Note: By default, com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer is used which handles type detection ### using generics. com.opensymphony.xwork2.util.GenericsObjectTypeDeterminer was deprecated since XWork 2, it's ### functions are integrated in DefaultObjectTypeDeterminer now. ### To disable tiger support use the "notiger" property value here. #struts.objectTypeDeterminer = tiger #struts.objectTypeDeterminer = notiger ### Parser to handle HTTP POST requests, encoded using the MIME-type multipart/form-data # struts.multipart.parser=cos # struts.multipart.parser=pell struts.multipart.parser=jakarta # uses javax.servlet.context.tempdir by default struts.multipart.saveDir= struts.multipart.maxSize=20971520 ### Load custom property files (does not override struts.properties!) # struts.custom.properties=application,org/apache/struts2/extension/custom ### How request URLs are mapped to and from actions #struts.mapper.class=org.apache.struts2.dispatcher.mapper.DefaultActionMapper ### Used by the DefaultActionMapper ### You may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do ### The blank extension allows you to match directory listings as well as pure action names ### without interfering with static resources. struts.action.extension=action,, ### Used by FilterDispatcher ### If true then Struts serves static content from inside its jar. ### If false then the static content must be available at <context_path>/struts struts.serve.static=true ### Used by FilterDispatcher ### This is good for development where one wants changes to the static content be ### fetch on each request. ### NOTE: This will only have effect if struts.serve.static=true ### If true -> Struts will write out header for static contents such that they will ### be cached by web browsers (using Date, Cache-Content, Pragma, Expires) ### headers). ### If false -> Struts will write out header for static contents such that they are ### NOT to be cached by web browser (using Cache-Content, Pragma, Expires ### headers) struts.serve.static.browserCache=true ### Set this to false if you wish to disable implicit dynamic method invocation ### via the URL request. This includes URLs like foo!bar.action, as well as params ### like method:bar (but not action:foo). ### An alternative to implicit dynamic method invocation is to use wildcard ### mappings, such as <action name="*/*" method="{2}" class="actions.{1}"> struts.enable.DynamicMethodInvocation = true ### Set this to true if you wish to allow slashes in your action names. If false, ### Actions names cannot have slashes, and will be accessible via any directory ### prefix. This is the traditional behavior expected of WebWork applications. ### Setting to true is useful when you want to use wildcards and store values ### in the URL, to be extracted by wildcard patterns, such as ### <action name="*/*" method="{2}" class="actions.{1}"> to match "/foo/edit" or ### "/foo/save". struts.enable.SlashesInActionNames = false ### use alternative syntax that requires %{} in most places ### to evaluate expressions for String attributes for tags struts.tag.altSyntax=true ### when set to true, Struts will act much more friendly for developers. This ### includes: ### - struts.i18n.reload = true ### - struts.configuration.xml.reload = true ### - raising various debug or ignorable problems to errors ### For example: normally a request to foo.action?someUnknownField=true should ### be ignored (given that any value can come from the web and it ### should not be trusted). However, during development, it may be ### useful to know when these errors are happening and be told of ### them right away. struts.devMode = false ### when set to true, resource bundles will be reloaded on _every_ request. ### this is good during development, but should never be used in production struts.i18n.reload=false ### Standard UI theme ### Change this to reflect which path should be used for JSP control tag templates by default struts.ui.theme=xhtml struts.ui.templateDir=template #sets the default template type. Either ftl, vm, or jsp struts.ui.templateSuffix=ftl ### Configuration reloading ### This will cause the configuration to reload struts.xml when it is changed struts.configuration.xml.reload=false ### Location of velocity.properties file. defaults to velocity.properties struts.velocity.configfile = velocity.properties ### Comma separated list of VelocityContext classnames to chain to the StrutsVelocityContext struts.velocity.contexts = ### Location of the velocity toolbox struts.velocity.toolboxlocation= ### used to build URLs, such as the UrlTag struts.url.http.port = 80 struts.url.https.port = 443 ### possible values are: none, get or all struts.url.includeParams = none ### Load custom default resource bundles # struts.custom.i18n.resources=testmessages,testmessages2 ### workaround for some app servers that don't handle HttpServletRequest.getParameterMap() ### often used for WebLogic, Orion, and OC4J struts.dispatcher.parametersWorkaround = false ### configure the Freemarker Manager class to be used ### Allows user to plug-in customised Freemarker Manager if necessary ### MUST extends off org.apache.struts2.views.freemarker.FreemarkerManager #struts.freemarker.manager.classname=org.apache.struts2.views.freemarker.FreemarkerManager ### Enables caching of FreeMarker templates ### Has the same effect as copying the templates under WEB_APP/templates struts.freemarker.templatesCache=false ### Enables caching of models on the BeanWrapper struts.freemarker.beanwrapperCache=false ### See the StrutsBeanWrapper javadocs for more information struts.freemarker.wrapper.altMap=true ### maxStrongSize for MruCacheStorage for freemarker struts.freemarker.mru.max.strong.size=100 ### configure the XSLTResult class to use stylesheet caching. ### Set to true for developers and false for production. struts.xslt.nocache=false ### Whether to always select the namespace to be everything before the last slash or not struts.mapper.alwaysSelectFullNamespace=false ### Whether to allow static method access in OGNL expressions or not struts.ognl.allowStaticMethodAccess=true ### Whether to throw a RuntimeException when a property is not found ### in an expression, or when the expression evaluation fails struts.el.throwExceptionOnFailure=false ### Logs as Warnings properties that are not found (very verbose) struts.ognl.logMissingProperties=false ### Caches parsed OGNL expressions, but can lead to memory leaks ### if the application generates a lot of different expressions struts.ognl.enableExpressionCache=true ### END SNIPPET: complete_file


struts.xml<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "http://struts.apache.org/dtds/struts-2.1.7.dtd"> <struts> <package name="dexopen" extends="struts-default"> <global-results> <result name="input" >/pages/admin/error.jsp</result> <result name="error" >/pages/admin/error.jsp</result> <result name="notLogin">/pages/admin/forword.jsp</result> </global-results> <global-exception-mappings> <exception-mapping result="error" exception="java.lang.Exception"></exception-mapping> </global-exception-mappings> </package> <!-- action命名空间对应jsp的默认路径配置 --> <constant name="struts.convention.result.path" value="/WEB-INF/pages"/> <constant name="struts.convention.default.parent.package" value="dexopen"/> </struts>
好了,至此为止整个项目已经配置完毕,目录结构应该如下所示
现在可以开始进行测试的工作了。
然后我们在eclipse里面直接通过tomcat运行的话,会报找不到类的错误,这是因为在eclipse里面直接运行的时候,依赖的jar包没有跟随项目一同发布,杯具的是笔者至今不知道该怎么解决,望大大支招,不过笔者有另外的办法。
在项目上右键->Run->Maven install…直到控制台输出下面的信息后,就说明项目打包成功了
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:07.687s
[INFO] Finished at: Sun May 20 17:43:37 CST 2012
[INFO] Final Memory: 6M/13M
[INFO] ------------------------------------------------------------------------
对项目进行刷新操作,然后可以看到target里面已经有相应的内容了,我们把WEB-INF/lib目录覆盖到
你的工作空间\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ssh_demo\WEB-INF
再次运行之后就没问题了。tomcat输出信息如下
2012-5-20 18:09:31 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Java\jdk1.6.0_10\bin;C:\Program Files\Windows Live\Shared
2012-5-20 18:09:31 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ssh_demo' did not find a matching property.
2012-5-20 18:09:31 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2012-5-20 18:09:31 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 433 ms
2012-5-20 18:09:31 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2012-5-20 18:09:31 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.26
log4j:WARN No such property [maxFileSize] in org.apache.log4j.FileAppender.
2012-5-20 18:09:32 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2012-5-20 18:09:36 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2012-5-20 18:09:36 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2012-5-20 18:09:36 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/41 config=null
2012-5-20 18:09:36 org.apache.catalina.startup.Catalina start
信息: Server startup in 5061 ms
好了,至此为止从搭建maven私服到集成eclipse到通过maven集成ssh项目,整个系列全部完成(卧槽,尼玛终于写完了)。
这里提供项目的源文件下载:http://115.com/file/anromexp#