摘要
最近也在网上找了些教程,试着使用maven进行包依赖关系的管理,也尝试着通过注解的方式来整合ssh框架。在这个过程中,踩了不少的坑。折腾很长时间,才算把架子折腾起来。这里把结果整理下,作为以后工作中的参考。
项目结构
关于maven如何使用,可自行搜索,默认你有一定的maven基础。maven建议中央仓库配置成阿里云的,可以下载速度快一些。地址
1、开始之前,需要通过maven进行ssh jar包引入。可以参考下面的pom.xml
encoding=?>
xsi:schemaLocation=<span style="color: #800000;">"<span style="color: #800000;">http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd<span style="color: #800000;">">.
<project xmlns=<span style="color: #800000;">"
<span style="color: #800000;">http://maven.apache.org/POM/4.0.0<span style="color: #800000;">" xmlns:xsi=<span style="color: #800000;">"<span style="color: #800000;">http://www.w3.org/2001/XMLSchema-instance<span style="color: #800000;">"<span style="color: #000000;">xsi:schemaLocation=<span style="color: #800000;">"<span style="color: #800000;">http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd<span style="color: #800000;">">
<groupId>com.demo</groupId>
<artifactId>mavenapp</artifactId>
<version><span style="color: #800080;">1.0</span>-SNAPSHOT</version>
<packaging>war</packaging>
<name>mavenapp Maven Webapp</name>
<!-- FIXME change it to the project<span style="color: #800000;">'</span><span style="color: #800000;">s website --></span>
<url>http:<span style="color: #008000;">//</span><span style="color: #008000;">www.example.com</url></span>
<properties>
<!--源码编码-->
<project.build.sourceEncoding>UTF-<span style="color: #800080;">8</span></project.build.sourceEncoding>
<maven.compiler.source><span style="color: #800080;">1.7</span></maven.compiler.source>
<maven.compiler.target><span style="color: #800080;">1.7</span></maven.compiler.target>
<!-- spring版本号 -->
<spring.version><span style="color: #800080;">4.3</span>.<span style="color: #800080;">8</span>.RELEASE</spring.version>
<!-- hibernate版本号 -->
<hibernate.version><span style="color: #800080;">5.1</span>.<span style="color: #800080;">7</span>.Final</hibernate.version>
<!-- struts2版本号 -->
<struts2.version><span style="color: #800080;">2.5</span>.<span style="color: #800080;">10</span></struts2.version>
</properties>
<dependencies>
<!--JUnit4依赖-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version><span style="color: #800080;">4.12</span></version>
<scope>test</scope>
</dependency>
<!-- Spring 核心依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring web依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring整合ORM框架依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Struts2 核心依赖 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
</dependency>
<!-- Struts2和Spring整合依赖 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<!-- Hibernate 核心依赖 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- MySQL 依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version><span style="color: #800080;">5.1</span>.<span style="color: #800080;">42</span></version>
</dependency>
<!-- C3P0 依赖 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version><span style="color: #800080;">0.9</span>.<span style="color: #800080;">5</span></version>
</dependency>
<!-- AspectJ依赖 -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version><span style="color: #800080;">1.8</span>.<span style="color: #800080;">10</span></version>
</dependency>
<!-- SLF4J依赖 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version><span style="color: #800080;">1.7</span>.<span style="color: #800080;">25</span></version>
</dependency>
</dependencies>
<build>
<finalName>mavenapp</finalName>
<pluginManagement><!-- <span style="color: #0000ff;">lock</span> down plugins versions to avoid <span style="color: #0000ff;">using</span> Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version><span style="color: #800080;">3.0</span>.<span style="color: #800080;">0</span></version>
</plugin>
<!-- see http:<span style="color: #008000;">//</span><span style="color: #008000;">maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --></span>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version><span style="color: #800080;">3.0</span>.<span style="color: #800080;">2</span></version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version><span style="color: #800080;">3.7</span>.<span style="color: #800080;">0</span></version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version><span style="color: #800080;">2.20</span>.<span style="color: #800080;">1</span></version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version><span style="color: #800080;">3.2</span>.<span style="color: #800080;">0</span></version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version><span style="color: #800080;">2.5</span>.<span style="color: #800080;">2</span></version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version><span style="color: #800080;">2.8</span>.<span style="color: #800080;">2</span></version>
</plugin>
</plugins>
</pluginManagement>
</build>