java-maven项目中出现Cannot resolve————已解决

本文详细阐述了在pom.xml中遇到'Cannot resolve xxx...'问题的解决步骤,包括检查Maven环境、配置、本地服务器路径、镜像,以及清理缓存、重启编译器等实用技巧。

Resolve dependencies Cannot resolve xxx…

主要出现在pom.xml文件中

首先判断自己的maven是否存在

win+R  输入cmd      输出mvn  —V

确定是有maven环境

然后就是在编译器中检查maven的配置

在这里插入图片描述

  • 对应就是检查对应本地服务器存放路径是否正确,对应。 对应的镜像是否正确

然后就是重新加载pom.xml

首先就是清理一下当前的缓存

在这里插入图片描述

方法 1
在这里插入图片描述

方法 2
在这里插入图片描述
方法 3
在这里插入图片描述

重新启动一下编译器 再试试

[root@yfw ~]# cd /opt/openfire [root@yfw openfire]# # 1. 回到家目录,创建独立的插件项目 [root@yfw openfire]# cd ~ [root@yfw ~]# mkdir -p openfire-plugins/restapi-plugin/src/main/{java,resources} out.println("🛑 REST API Plugin 已[root@yfw ~]# [root@yfw ~]# # 2. 进入项目根目录 [root@yfw ~]# cd openfire-plugins/restapi-plugin [root@yfw restapi-plugin]# [root@yfw restapi-plugin]# # 3. 创建 pom.xml [root@yfw restapi-plugin]# cat > pom.xml << 'EOF' > <?xml version="1.0" encoding="UTF-8"?> > <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> > <modelVersion>4.0.0</modelVersion> > <groupId>com.example.openfire.plugins</groupId> > <artifactId>restapi-plugin</artifactId> > <version>1.0.0-SNAPSHOT</version> > <packaging>jar</packaging> > <properties> > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> > <maven.compiler.source>17</maven.compiler.source> > <maven.compiler.target>17</maven.compiler.target> > <openfire.version>4.9.2</openfire.version> > </properties> > <dependencies> > <dependency> > <groupId>org.igniterealtime.openfire</groupId> > <artifactId>openfire</artifactId> > <version>${openfire.version}</version> > <scope>provided</scope> > </dependency> > </dependencies> > <build> > <plugins> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-compiler-plugin</artifactId> > <version>3.11.0</version> > <configuration> > <source>17</source> > <target>17</target> > </configuration> > </plugin> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-assembly-plugin</artifactId> > <version>3.6.0</version> > <executions> > <execution> > <phase>package</phase> > <goals> > <goal>single</goal> > </goals> > <configuration> > <descriptorRefs> > <descriptorRef>jar-with-dependencies</descriptorRef> > </descriptorRefs> > <finalName>${project.artifactId}-assembly</finalName> > <appendAssemblyId>false</appendAssemblyId> > </configuration> > </execution> > </executions> > </plugin> > </plugins> > <resources> > <resource> > <directory>src/main/resources</directory> > <filtering>true</filtering> > <includes><include>plugin.xml</include></includes> > </resource> > <resource> > <directory>src/main/resources</directory> > <filtering>false</filtering> > <excludes><exclude>plugin.xml</exclude></excludes> > </resource> > </resources> > </build> > <repositories> > <repository> > <id>igniterealtime-repo</id> > <url>https://www.igniterealtime.org/repo/maven2/</url> > </repository> > </repositories> > </project> > EOF [root@yfw restapi-plugin]# [root@yfw restapi-plugin]# # 4. 创建 plugin.xml [root@yfw restapi-plugin]# cat > src/main/resources/plugin.xml << 'EOF' > <?xml version="1.0" encoding="UTF-8"?> > <plugin> > <className>com.example.restapi.RestApiPlugin</className> > <name>REST API Plugin</name> > <description>Provides REST APIs.</description> > <author>Your Name</author> > <version>1.0.0</version> > <date>2025-10-03</date> > <minServerVersion>4.9.2</minServerVersion> > </plugin> > EOF [root@yfw restapi-plugin]# [root@yfw restapi-plugin]# # 5. 创建 Java 类 [root@yfw restapi-plugin]# cat > src/main/java/com/example/restapi/RestApiPlugin.java << 'EOF' > package com.example.restapi; > > import org.jivesoftware.openfire.plugin.Plugin; > import org.jivesoftware.openfire.plugin.PluginManager; > import java.io.File; > > public class RestApiPlugin implements Plugin { > @Override > public void initializePlugin(PluginManager manager, File pluginDirectory) { > System.out.println("✅ REST API Plugin 已成功加载!"); > } > > @Override > public void destroyPlugin() { > System.out.println("🛑 REST API Plugin 已卸载。"); > } > } > EOF -bash: src/main/java/com/example/restapi/RestApiPlugin.java: No such file or directory [root@yfw restapi-plugin]# [root@yfw restapi-plugin]# # 6. 构建项目 [root@yfw restapi-plugin]# mvn clean package [INFO] Scanning for projects... [INFO] [INFO] ------------< com.example.openfire.plugins:restapi-plugin >------------- [INFO] Building restapi-plugin 1.0.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.11.0/maven-compiler-plugin-3.11.0.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.11.0/maven-compiler-plugin-3.11.0.pom (9.8 kB at 5.3 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/39/maven-plugins-39.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/39/maven-plugins-39.pom (8.1 kB at 16 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.11.0/maven-compiler-plugin-3.11.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.11.0/maven-compiler-plugin-3.11.0.jar (66 kB at 94 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/2.4/maven-jar-plugin-2.4.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/2.4/maven-jar-plugin-2.4.pom (5.8 kB at 12 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/2.4/maven-jar-plugin-2.4.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/2.4/maven-jar-plugin-2.4.jar (34 kB at 67 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/3.6.0/maven-assembly-plugin-3.6.0.pom Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/3.6.0/maven-assembly-plugin-3.6.0.pom (15 kB at 32 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/3.6.0/maven-assembly-plugin-3.6.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/3.6.0/maven-assembly-plugin-3.6.0.jar (236 kB at 320 kB/s) Downloading from igniterealtime-repo: https://www.igniterealtime.org/repo/maven2/org/igniterealtime/openfire/openfire/4.9.2/openfire-4.9.2.pom Downloading from central: https://repo.maven.apache.org/maven2/org/igniterealtime/openfire/openfire/4.9.2/openfire-4.9.2.pom [WARNING] The POM for org.igniterealtime.openfire:openfire:jar:4.9.2 is missing, no dependency information available Downloading from igniterealtime-repo: https://www.igniterealtime.org/repo/maven2/org/igniterealtime/openfire/openfire/4.9.2/openfire-4.9.2.jar Downloading from central: https://repo.maven.apache.org/maven2/org/igniterealtime/openfire/openfire/4.9.2/openfire-4.9.2.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 8.672 s [INFO] Finished at: 2025-10-03T01:49:40+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project restapi-plugin: Could not resolve dependencies for project com.example.openfire.plugins:restapi-plugin:jar:1.0.0-SNAPSHOT: Could not find artifact org.igniterealtime.openfire:openfire:jar:4.9.2 in igniterealtime-repo (https://www.igniterealtime.org/repo/maven2/) -> [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/DependencyResolutionException [root@yfw restapi-plugin]# [root@yfw restapi-plugin]# # 7. 部署到 Openfire [root@yfw restapi-plugin]# cp target/restapi-plugin-assembly.jar /opt/openfire/plugins/ cp: cannot stat 'target/restapi-plugin-assembly.jar': No such file or directory [root@yfw restapi-plugin]# [root@yfw restapi-plugin]# # 8. 查看日志 [root@yfw restapi-plugin]# tail -f /opt/openfire/logs/openfire.log at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) [netty-transport-4.1.108.Final.jar:4.1.108.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) [netty-transport-4.1.108.Final.jar:4.1.108.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) [netty-transport-4.1.108.Final.jar:4.1.108.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) [netty-transport-4.1.108.Final.jar:4.1.108.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) [netty-common-4.1.108.Final.jar:4.1.108.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-common-4.1.108.Final.jar:4.1.108.Final] at java.lang.Thread.run(Thread.java:829) [?:?] 2025.10.03 01:33:56.063 ERROR [socket_c2s-thread-8]: org.jivesoftware.openfire.nio.NettyConnection - Problem during connection close or cleanup io.netty.channel.StacklessClosedChannelException: null at io.netty.channel.AbstractChannel$AbstractUnsafe.write(Object, ChannelPromise)(Unknown Source) ~[netty-transport-4.1.108.Final.jar:4.1.108.Final]
10-04
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值