pom.xml中的相关配置

本文详细介绍了Spring框架的各种核心模块依赖,包括spring-core、spring-beans、spring-context等,以及与之配套的事务管理、Web开发、MyBatis整合、数据库连接池等关键组件。
<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>            
        </dependency>
<!-- spring start -->
        <!-- 1 包含spring框架基本的核心工具类。spring其他组件都要使用到这个包里面的类,是其他组件的基本核心 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <!--2 这个jar文件是所有类都要用到的,包含访问配置文件、创建和管理bean以及进行ioc/di操作相关的类,如果应用只需要基本的ioc/di操作,引入这个文件即可 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <!-- 3 这个jar文件为spring核心提供大量扩展。可以找到使用 spring applicationContext特性时所需的全部所需的全部 
            了类,instrumentation组件以及校验validation方面的相关类 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <!-- 4 包含spring对jdbc数据访问进行封装的所有类 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${srping.version}</version>
            <!-- 5 为jdbc、hibernate、jdo、jpa等提供的一致 的声名式和编程式事务管理 -->
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <!-- 6 包含web应用开发时,用到spring框架时所需的核心类,包括自动载入webapplicationContext-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <!-- 7 包含springmvc框架相关的所有类-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <!-- 8  对junit等测试框架简单的封装-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${srping.version}</version>
        </dependency>
<!-- spring end -->    
<!-- servlet-api -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>    
<!-- servlet-api -->
<!--json解析  前端数据交换 -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.8.7</version>
    </dependency>
 <!--json解析  -->
 <!-- map工具类 -->
<!--     <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>jcommons-collections</artifactId>
        <version>3.2</version>
    </dependency> -->
 <!-- mybatis框架包 start -->    
        <dependency>    
            <groupId>org.mybatis</groupId>    
            <artifactId>mybatis</artifactId>    
            <version>3.4.2</version>    
        </dependency>    
        <dependency>    
            <groupId>org.mybatis</groupId>    
            <artifactId>mybatis-spring</artifactId>    
            <version>1.3.1</version>    
        </dependency>    
 <!-- mybatis框架包 end -->  
 <!-- 数据库驱动 -->    
        <dependency>    
            <groupId>mysql</groupId>    
            <artifactId>mysql-connector-java</artifactId>    
            <version>5.1.35</version>    
        </dependency>  
  <!-- 导入c3p0的jar包,用来在applicationContext.xml中配置数据库 -->    
        <dependency>    
            <groupId>c3p0</groupId>    
            <artifactId>c3p0</artifactId>    
            <version>0.9.1.2</version>    
        </dependency> 
            <!-- https://mvnrepository.com/artifact/net.coobird/thumbnailator -->
            <!-- 图片处理 -->
        <dependency>
    <groupId>net.coobird</groupId>
    <artifactId>thumbnailator</artifactId>
    <version>0.4.8</version>
</dependency>  
<!-- https://mvnrepository.com/artifact/com.github.penggle/kaptcha -->
<!-- 验证码 -->
<dependency>
    <groupId>com.github.penggle</groupId>
    <artifactId>kaptcha</artifactId>
    <version>2.3.2</version>
</dependency>
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.2</version>
</dependency>
    </dependencies>
    <build>
        <finalName>O2O</finalName>
        <plugins>
            <!-- 设置编译版本为1.7 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration> 
            </plugin>
        </plugins>
    </build>

 

<think>嗯,用户现在问的是如何配置pom.xml来使用Nexus仓库。之前他们已经遇到了无法拉取依赖的问题,我之前已经给出了一些常见原因和解决办法,其中提到了Maven配置的问题,括settings.xmlpom.xml。现在用户可能想更详细地了解pom.xml的具体配置步骤,而不仅仅是示例片段。 首先,我需要回顾用户之前的提问历史。他们之前的问题是关于无法从Nexus拉取依赖的可能原因,现在转向了pom.xml配置。这说明用户可能已经检查了网络、权限等问题,现在需要更具体的配置指导。或者他们可能在尝试按照之前的建议修改配置后,仍然遇到问题,需要更详细的步骤。 接下来,我需要确定用户的使用场景。用户很可能是开发人员,负责项目构建,可能在使用Maven管理依赖,公司内部使用Nexus作为私有仓库。他们需要正确配置项目的pom.xml,以便从Nexus获取依赖,也可能需要将项目部署到Nexus。此外,用户可能对Maven配置不太熟悉,需要清晰的步骤和示例。 然后,分析用户可能没有直接表达的深层需求。用户可能需要知道如何同时配置依赖和插件仓库,如何区分发布版本和快照版本,如何处理认证信息是否应该放在pom.xml中,以及部署配置的具体方法。他们可能还关心最佳实践,比如是否推荐在pom.xml中直接配置仓库,还是更推荐使用settings.xml。 现在需要组织回答的结构。首先应该说明在pom.xml配置仓库的基本方法,括添加repositories和pluginRepositories。然后可能需要提到认证信息通常不建议放在pom.xml中,而是放在settings.xml里。接着,如果用户需要部署构件到Nexus,需要配置distributionManagement部分。此外,需要提醒用户关于仓库ID与server的匹配,快照和发布的启用设置,以及仓库顺序的影响。 还要注意用户可能存在的误区,例如直接在pom.xml中写密码,这可能不安全,应该指出正确的做法。另外,是否需要配置镜像,这通常在settings.xml中处理,但可能也需要提及。此外,可能涉及快照版本和发布版本的不同仓库配置,以及多仓库情况下的优先级问题。 最后,要确保回答清晰,步骤明确,示例正确,并且符合之前提到的系统级指令,比如使用正确的LaTeX格式,分点说明,结构清晰。同时,检查是否有遗漏的情况,比如多模块项目是否需要特殊处理,或者是否需要考虑仓库的布局策略等,但可能这些属于进阶内容,暂时不需要深入,除非用户进一步询问。</think>以下是 `pom.xml` 中配置 Nexus 仓库的详细步骤和注意事项: --- ### **1. 基础配置:添加仓库地址** 在 `pom.xml` 的 `<repositories>` 和 `<pluginRepositories>` 标签中定义 Nexus 仓库地址。 - **依赖仓库**(`<repositories>`):用于拉取项目依赖。 - **插件仓库**(`<pluginRepositories>`):用于拉取 Maven 插件依赖。 #### 示例代码: ```xml <project> ... <repositories> <repository> <id>nexus-public</id> <!-- 仓库唯一标识,需与 settings.xml 中的 server 匹配 --> <name>Nexus Public Repository</name> <url>http://your-nexus-server/repository/maven-public/</url> <releases> <enabled>true</enabled> <!-- 启用发布版本 --> </releases> <snapshots> <enabled>true</enabled> <!-- 启用快照版本 --> <updatePolicy>always</updatePolicy> <!-- 强制每次更新检查 --> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus-public</id> <!-- 与 repository 的 id 保持一致 --> <url>http://your-nexus-server/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> ... </project> ``` --- ### **2. 认证信息(推荐通过 settings.xml 配置)** **不建议直接在 `pom.xml` 中明文存储用户名和密码**。 正确的做法是在 Maven 的全局/用户 `settings.xml` 中配置 `<server>` 信息,且 `<server>` 的 `<id>` 需与仓库的 `<id>` 一致。 #### settings.xml 示例: ```xml <settings> <servers> <server> <id>nexus-public</id> <!-- 必须与 pom.xml 中仓库的 id 一致 --> <username>deployment-user</username> <password>your-encrypted-password</password> </server> </servers> </settings> ``` --- ### **3. 部署构件到 Nexus(可选)** 若需将项目构建的 jar 或镜像发布到 Nexus,需配置 `<distributionManagement>` 标签: #### 部署配置示例: ```xml <project> ... <distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://your-nexus-server/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://your-nexus-server/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement> ... </project> ``` --- ### **4. 关键注意事项** 1. **仓库 ID 一致性** - `<repository>` 的 `<id>` 必须与 `settings.xml` 中的 `<server>` 的 `<id>` 完全匹配,否则认证失败。 2. **快照与发布分离** - 建议为快照(`SNAPSHOT`)和发布版本(`RELEASE`)配置不同的仓库路径(如 `maven-snapshots` 和 `maven-releases`),避免混用。 3. **仓库优先级** - Maven 默认会优先使用中央仓库(`central`)。若需强制优先从 Nexus 拉取依赖,可关闭中央仓库: ```xml <repository> <id>central</id> <url>http://dummy-url</url> <!-- 覆盖默认中央仓库 --> <releases><enabled>false</enabled></releases> <snapshots><enabled>false</enabled></snapshots> </repository> ``` 4. **镜像配置(更推荐)** - 更简洁的方式是在 `settings.xml` 中通过 `<mirror>` 将所有请求重定向到 Nexus(无需修改 `pom.xml`)。 --- ### **5. 验证配置是否生效** 执行以下命令检查依赖解析路径: ```bash mvn dependency:resolve -Dverbose ``` 观察日志中依赖的下载地址是否指向 Nexus 仓库。若仍从中央仓库下载,需检查配置覆盖逻辑。 --- ### **总结** - **简单场景**:优先通过 `settings.xml` 配置全局仓库和镜像,减少 `pom.xml` 的侵入性。 - **多仓库管理**:在 `pom.xml` 中显式声明仓库地址,适用于需要混合使用多个私有仓库的情况。 - **安全原则**:**永远不要在 `pom.xml` 中明文存储密码**,敏感信息应通过 `settings.xml` 加密管理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值