Java 11:为什么“导入xxx无法解析”,即使有模块信息通知它是必需的

问题描述 投票:1回答:1

我已经阅读了自Java 9以来的模块化。我知道我必须创建一个模块信息和infor哪个包是公开和需要的。我可以看到我的classpath上有Java 11。但是我收到了关于主题的错误。更准确地说,在构建时,我得到了这个错误日志

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

我缺少一些额外的设置,以使从普通项目的类可见到其他项目?

PS1:我跟随Import XXX cannot be resolved for Java SE standard classes并设置为替代JRE。 PS2。:我认为这与Eclipse有关。顺便说一下,我正在使用这个版本:

适用于企业Java开发人员的Eclipse IDE。版本:2018-12(4.10.0)Build ID:20181214-0600 OS:Windows 10,v.10.0,x86_64 / win32 Java版本:11.0.2

在我的zuul项目中:

import com.test.common.security.JwtConfig;

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

...

module-info.Java

module zuul {
...
    requires common;

}

在我的共同项目中

@Getter
@ToString
public class JwtConfig {

...

module-info.Java

module common {
    exports com.test.common.security;
    exports com.test.common;
...
}
eclipse java-9 java-11
1个回答
2
投票

我发现了这个问题。对于那些对Java9 +更有经验的人来说,这似乎是非常愚蠢的,但对我来说,需要一段时间才能找到根本原因。希望它对未来的读者有用。

问题:常见的项目是在classpath而不是module-path

enter image description here

解决方案:当我移交需要通用时,只需移动到Eclipse的sugested模块路径;在module-info.java中当我发现import com.test.common.security.JwtConfig;在SecurityTokenConfig.java上,提出的解决方案与我移交module-info.java时的解决方案完全不同(可能对Eclipse团队提出的适度建议将从现在开始对其进行修改,但这超出了此问题的目的)。

enter image description here

积分兑换https://www.eclipse.org/community/eclipse_newsletter/2018/june/java9andbeyond.php

***编辑

虽然我仍然认为上述解决方案是我的问题的答案,但我必须承认,在解决了这个问题之后,我偶然发现了一个新问题,我意识到,至少在我的情况下,即使使用Java 11,我也必须避免模块化(Jigsaw)。未来的读者也可能对这个帖子感兴趣

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

© www.soinside.com 2019 - 2024. All rights reserved.