maven中央仓库不能访问的解决办法

文章详细介绍了如何通过设置Maven配置文件中的代理或镜像来解决Maven项目编译时无法访问apache.org/maven2网站的问题,确保了项目的正常构建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

导入Maven项目,编译时候出错,好象是接不上apache.org/maven2,下载不了maven-resources-plugin-2.6.jar 这个jar包

出错内容:

Plain Text code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-01 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.234 s
[INFO] Finished at: 2014-09-05T09:57:26+08:00
[INFO] Final Memory: 2M/6M
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from/to central (https://repo.maven.apache.org/maven2): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException


网上查了一下,无法访问maven.org网站的解决此问题理论上有两个办法,一个是在maven的配置文件中设置代理,另一个是在maven的配置文件中设置联通网络下,能够访问的中央仓库的mirrors。因为也不好找稳定的代理,在网上搜索了两个可用的mirror站点,配置方式如下:

1、打开maven配置文件(maven安装目录下的conf目录下的settings.xml文件)

2、搜索mirrors关键字,加入mirror镜像节点

<mirror> 
           <id>ibiblio.org</id> 
           <name>ibiblio Mirror of http://repo1.maven.org/maven2/</name> 
           <url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url> 
           <mirrorOf>central</mirrorOf> 
           <!-- United States, North Carolina --> 
     </mirror>
     <mirror>  
         <id>jboss-public-repository-group</id>  
         <mirrorOf>central</mirrorOf>  
         <name>JBoss Public Repository Group</name>  
         <url>http://repository.jboss.org/nexus/content/groups/public</url>  
     </mirror>

但是这两个也不好用,在这里使用 OSC Maven 仓库找到开源中国的资源库,

配置了他们的镜像

<mirror>
        <id>osc</id>
        <mirrorOf>*</mirrorOf>
        <url>http://maven.oschina.net/content/groups/public/</url>
    </mirror>


成功编译。



<think>嗯,用户想在Maven项目中引入PageHelper分页插件,但可能遇到了依赖配置的问题。我需要先整理一下提供的引用内容,看看里面提到的步骤和常见问题。 根据引用[1],用户需要添加PageHelper的依赖,指定groupId和artifactId,还有版本号。引用[2]和[4]给出了不同的依赖配置,特别是引用[2]提到了使用starter版本,而引用[4]是较旧的版本,还包含jsqlparser的依赖。这说明版本不同可能导致配置方式不同,特别是5.0以上和以下版本的差异,如引用[3]提到的拦截器类名的变化。 用户可能需要选择适合的版本,比如最新的或者稳定的。引用[3]提到版本不匹配会导致类找不到的错误,所以版本号要正确。另外,引用[5]指出Maven仓库路径的问题,如果配置错误,可能无法下载依赖,这也是需要注意的地方。 接下来,我应该分步骤说明如何配置依赖,包括普通项目和Spring Boot项目的不同情况。同时提醒用户检查Maven配置,避免路径或仓库问题。还要提到MyBatis配置文件中拦截器的设置,因为版本不同会影响类名,比如PageInterceptor和PageHelper的区别。 最后,常见问题部分需要涵盖版本兼容性、依赖冲突和配置检查,这些都是用户可能遇到的坑。需要确保用户按照正确的步骤操作,并给出验证方法,比如分页查询是否生效。</think>### 如何在 Maven 项目中配置 PageHelper 分页插件依赖? #### 步骤 1:添加 Maven 依赖 根据项目类型选择依赖配置: - **普通 Maven 项目**(非 Spring Boot): ```xml <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.3.3</version> <!-- 建议使用最新稳定版本 --> </dependency> ``` 同时需要添加 `jsqlparser` 依赖(部分版本已自动包含)[^4]: ```xml <dependency> <groupId>com.github.jsqlparser</groupId> <artifactId>jsqlparser</artifactId> <version>4.6</version> </dependency> ``` - **Spring Boot 项目**(推荐使用 starter): ```xml <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.4.3</version> <!-- 根据Spring Boot版本选择 --> </dependency> ``` 该方式会自动处理 MyBatis 集成和版本兼容性[^2]。 #### 步骤 2:配置 MyBatis 拦截器 在 `mybatis-config.xml` 中增加插件配置(仅非 Spring Boot 项目需要): ```xml <configuration> <plugins> <!-- PageHelper 5.0+ 使用 PageInterceptor --> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <property name="helperDialect" value="mysql"/> <!-- 指定数据库类型 --> </plugin> </plugins> </configuration> ``` 注意:**5.0 以下版本**需使用 `PageHelper` 类而非 `PageInterceptor`[^3]。 #### 步骤 3:验证 Maven 配置 1. 检查本地 Maven 仓库路径是否正确(避免指向默认 C 盘无效路径)[^5] 2. 执行 `mvn clean install` 确保依赖下载成功 3. 观察编译日志,排除依赖冲突(如 MyBatis/Spring 版本不兼容) #### 常见问题解决 - **类找不到错误**:通常因版本不匹配导致,例如: - 5.0+ 版本必须用 `PageInterceptor` - Spring Boot 项目优先使用 `starter` 依赖 - **分页失效**:检查是否在查询**前**调用 `PageHelper.startPage(pageNum, pageSize)` - **SQL 方言问题**:通过 `helperDialect` 属性明确指定数据库类型 #### 验证示例代码 ```java // 在查询方法中使用 PageHelper.startPage(1, 10); // 第一页,每页10条 List<User> users = userMapper.selectAll(); PageInfo<User> pageInfo = new PageInfo<>(users); ```
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值