首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java 11:为什么“无法解析导入xxx”,即使使用module-info通知它是必需的

Java 11:为什么“无法解析导入xxx”,即使使用module-info通知它是必需的
EN

Stack Overflow用户
提问于 2019-03-21 02:33:37
回答 1查看 3.1K关注 0票数 1

我从Java 9开始就读到了模块化的知识,我意识到我必须创建一个module-info和I,这个包是公开的,并且是必需的。我可以看到我的类路径中确实有Java 11。但是我得到了在主题中提到的错误。更准确地说,在构建时,我会得到这个错误日志

代码语言:javascript
复制
INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ zuul ---
[WARNING] Can't extract module name from xpp3_min-1.1.4c.jar: Provider class org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer not in module
[WARNING] ********************************************************************************************************************
[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *
[WARNING] ********************************************************************************************************************
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to C:\_d\WSs\soteste\zuul\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/_d/WSs/soteste/zuul/src/main/java/module-info.java:[24,18] module not found: common
[INFO] 1 error

我错过了一些额外的设置,以便使来自公共项目的类对其他项目可见?

JRE :我跟随Import XXX cannot be resolved for Java SE standard classes并设置到了alternative PS1。PS2:我不认为这和Eclipse有什么关系。顺便说一句,我使用的是这个版本:

面向企业Java开发人员的Eclipse IDE。版本:2018年-12 (4.10.0)内部版本id: 20181214-0600操作系统: Windows 10,v.10.0,x86_64 / win32 Java版本: 11.0.2

在我的zuul项目中:

代码语言:javascript
复制
import com.test.common.security.JwtConfig;

@EnableWebSecurity  
public class SecurityTokenConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private JwtConfig jwtConfig;

..。

module-info.java

代码语言:javascript
复制
module zuul {
...
    requires common;

}

在我的公共项目中

代码语言:javascript
复制
@Getter
@ToString
public class JwtConfig {

..。

module-info.java

代码语言:javascript
复制
module common {
    exports com.test.common.security;
    exports com.test.common;
...
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-21 03:29:26

我找到问题了。对于其他更有Java9+经验的人来说,这可能看起来很愚蠢,但对我来说,花了一段时间才找到根本原因。希望它能对未来的读者有用。

问题:公共项目位于类路径中,而不是模块路径中

解决方案:就像我移交时Eclipse建议的那样,移动到模块路径需要common;当我移交导入com.test.common.security.JwtConfig时,在SecurityTokenConfig.java -info.java中;在just上,提出的解决方案与我移交module-info.java时的解决方案不同(也许给Eclipse团队的一个适度建议是从现在开始审查它,但这超出了这个问题的目的)。

致谢给https://www.eclipse.org/community/eclipse_newsletter/2018/june/java9andbeyond.php

*已编辑

尽管我仍然认为上面的解决方案是我问题的答案,但我必须承认,在修复这个问题后,我偶然发现了一个新问题,并且我意识到,至少对于我的情况,即使使用Java11,我也必须避免模块化(Jigsaw)。将来的读者也可能对这个帖子感兴趣。

Java 11 without modularity: package does not exist while it is added as maven dependency

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55267898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档