Maven搭建(以及pom的配置)

Maven: 用来管理项目依赖,构件

maven中央库:http://repo1.maven.org/maven2/

maven国内镜像:http://maven.aliyun.com/nexus/content/groups/public

maven本地库:

查询maven依赖(http://mvnrepository.com/)

在maven库中,每个maven构建由Group Id, Artifact Id, Version唯一标识。

Maven环境搭建

1. 下载apache-maven-3.5.0-bin.zip

2. 修改conf目录下的setting.xml

//设置maven本地库

<localRepository>d:/.m2/repository</localRepository>

<!--设置maven镜像( 从哪下载) -->

<mirror>

<id>nexus-aliyun</id>

<mirrorOf>*</mirrorOf>

<name>Nexus aliyun</name>

<url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>

3. 在eclipse中配置maven

4. 创建maven工程(create a simple project(skip archetype selection))

填写Group Id, Artifact Id, Version

注意:第一个使用maven创建工程会比较慢,因为需要联网下载创建maven工程所必须的构建。

工程类型为war的工程需要web.xml(工程右键:JAVAEE Tools->Generate Deployement Descriptor

Stub)




5. 编写POM文件(depencies & build)

<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://ma

ven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.neuedu.test</groupId>

<artifactId>myvote</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>war</packaging>

<!--配置依赖 -->

<dependencies>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

<version>3.0.1</version>

<scope>provided</scope>

</dependency>

<!--<dependency>

<groupId>jstl</groupId>

<artifactId>jstl</artifactId>

<version>1.2</version>

</dependency> -->

<!-- 配置spring基础依赖 -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-beans</artifactId>

<version>4.2.5.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

<version>4.2.5.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-aop</artifactId>

<version>4.2.5.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-aspects</artifactId>

<version>4.2.5.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-tx</artifactId>

<version>4.2.5.RELEASE</version>

</dependency>

<!-- 配置spring数据库连接池 -->

<dependency>

<groupId>commons-pool</groupId>

<artifactId>commons-pool</artifactId>

<version>1.3</version>

</dependency>

<dependency>

<groupId>org.apache.commons</groupId>

<artifactId>commons-dbcp2</artifactId>

<version>2.0</version>

</dependency>

<!-- 配置springmvc功能 -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

<version>4.2.5.RELEASE</version>

</dependency>

<!-- 配置springmvc文件上传 -->

<dependency>

<groupId>commons-io</groupId>

<artifactId>commons-io</artifactId>

<version>1.3.2</version>

</dependency>

<dependency>

<groupId>commons-fileupload</groupId>

<artifactId>commons-fileupload</artifactId>

<version>1.3.1</version>

</dependency>

<!-- 配置spring jackson -->

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-databind</artifactId>

<version>2.5.3</version>

</dependency>

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-core</artifactId>

<version>2.5.3</version>

</dependency>

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-annotations</artifactId>

<version>2.5.3</version>

</dependency>

<!-- 配置mybatis -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jdbc</artifactId>

<version>4.2.5.RELEASE</version>

</dependency>

<dependency>

<groupId>org.mybatis</groupId>

<artifactId>mybatis</artifactId>

<version>3.2.7</version>

</dependency>

<!-- 配置mybatis和spring整合 -->

<dependency>

<groupId>org.mybatis</groupId>

<artifactId>mybatis-spring</artifactId>

<version>1.2.4</version>

</dependency>

<!-- 配置mysql依赖 -->

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.40</version>

</dependency>

</dependencies>

<!-- 配置build环境 -->

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.2</version>

<configuration>

<source>1.7</source>

<target>1.7</target>

<encoding>utf-8</encoding>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.tomcat.maven</groupId>

<artifactId>tomcat7-maven-plugin</artifactId>

<version>2.2</version>

<configuration>

<port>8080</port>

<path>/myvote</path>

</configuration>

</plugin>

</plugins>

</build>

</project>

Maven管理ojdbc14依赖:

方法1

注:没有Eclipse的,使用方法2解决。

1、在Eclipse左边的Project Explorer的空白处单击右键

2、依次选择Import -> Import… -> Maven -> Install or deploy an artifact to a Maven repository,然后点击“Next”按钮

3、进入导入界面,填写以下信息

Artifact file:本地ojdbc.jar的位置,我本机是D:\app\Lenovo\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar

Group Id、Artifact Id、Version

其他的不需要填,然后点“Finish”按钮。

4、完成后,打开用户目录下的.m2 -> repository目录,能够看到已经有ojdbc相关的文件夹了

5、然后在项目中通过以下maven依赖配置即可将ojdbc导入

<dependency>

    <groupId>ojdbc</groupId>

    <artifactId>ojdbc6</artifactId>

    <version>11.2.0.4</version>

</dependency>




//每一个项目都有自己的pom配置,以上仅供参考

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容