代码之家  ›  专栏  ›  技术社区  ›  Jim C

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

  •  0
  • Jim C  · 技术社区  · 6 年前

    我从Java9开始就读过模块化。我知道我必须创建一个模块信息和信息哪个包是公开的和必需的。我可以看到我的类路径上确实有Java11。但是我得到了这个话题上提到的错误。更准确地说,在构建时,我得到了这个错误日志

    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。

    面向企业Java开发人员的eclipseide。 版本:2018-12(4.10.0) 操作系统:Windows 10、v.10.0、x86\u 64/win32 Java版本:11.0.2

    在我的zul项目中:

    import com.test.common.security.JwtConfig;
    
    @EnableWebSecurity  
    public class SecurityTokenConfig extends WebSecurityConfigurerAdapter {
        @Autowired
        private JwtConfig jwtConfig;
    

    ...

    模块-信息.java

    module zuul {
    ...
        requires common;
    
    }
    

    在我共同的项目中

    @Getter
    @ToString
    public class JwtConfig {
    

    ...

    module common {
        exports com.test.common.security;
        exports com.test.common;
    ...
    }
    
    0 回复  |  直到 6 年前
        1
  •  3
  •   Jim C    6 年前

    我发现了问题。对于其他更熟悉Java9+的人来说,这可能看起来非常愚蠢,但对我来说,花了一段时间才找到根本原因。希望能对以后的读者有所帮助。

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

    enter image description here

    解决方案:只需移动到Eclipse在我移交requires common时建议的module path;in module-信息.java当我移交进口时com.test.common.security.JwtConfig;打开SecurityTokenConfig.java所提出的解决方案不同于我移交模块时的解决方案-信息.java(也许给Eclipse团队一个适度的建议从现在开始重新审视它,但它超出了这个问题的目的)。

    enter image description here

    学分 https://www.eclipse.org/community/eclipse_newsletter/2018/june/java9andbeyond.php

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