IntelliJ中Maven重载时找不到jaxws-ri:2.3.5依赖的问题
解决方案
1. 修复Maven依赖配置
com.sun.xml.ws:jaxws-ri是POM类型的聚合依赖,并非可直接引用的JAR包,当前配置会导致Maven无法找到对应资源。可选择两种方式修正:
方式一:直接引用核心实现模块
若仅需运行SOAP服务的核心功能,直接引入jaxws-rt(Endpoint类所在模块)即可:
<dependencies> <!-- 保留javax.jws-api依赖不变 --> <dependency> <groupId>javax.jws</groupId> <artifactId>javax.jws-api</artifactId> <version>1.1</version> </dependency> <!-- 替换jaxws-ri为jaxws-rt --> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>2.3.5</version> </dependency> </dependencies>
方式二:通过依赖管理导入聚合依赖
若需引入jaxws-ri的全套组件,在dependencyManagement中导入POM类型的jaxws-ri,再按需引用子模块:
<dependencyManagement> <dependencies> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-ri</artifactId> <version>2.3.5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>javax.jws</groupId> <artifactId>javax.jws-api</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> </dependency> </dependencies>
2. 强制刷新Maven缓存
错误提示表明Maven已缓存依赖查找失败的结果,需强制刷新:
- 在IntelliJ中:右键项目 → Maven → Reload Project(按住
Shift点击刷新按钮可触发强制刷新,等同于-U参数) - 或在终端执行命令:
mvn clean install -U
3. 适配Java 17兼容性
jaxws-ri 2.3.5原生支持Java 8~11,在Java 17下运行需添加模块化参数,在pom.xml中添加插件配置:
<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> <compilerArgs> <arg>--add-modules</arg> <arg>java.xml.ws</arg> </compilerArgs> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.2.2</version> <configuration> <argLine>--add-modules java.xml.ws</argLine> </configuration> </plugin> </plugins> </build>
验证操作
修改配置后执行Maven刷新,重新运行SimpleSOAPServer类,确认构建与运行均正常。
内容的提问来源于stack exchange,提问作者AlgorithmArtisan
相关产品推荐
相关产品推荐

