Eclipse is confused by imports (“accessible from more than one module”)

前端 未结 6 1739
予麋鹿
予麋鹿 2020-11-29 08:48

When referencing simple .jar files, Eclipse shows an error stating:

The package java.awt is accessible from more than one module: , jav

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 09:06

    I think my flavour of the problem might be useful.

    I got this error for classes under javax.xml.stream, by old Maven projects that depend on artifacts like xml-apis, stax-api, or geronimo-stax-api.

    Technically, the problem is what others have already said: those artifacts expose the javax.xml.* package without any awareness of Java modules (they were born earlier), so the package goes automatically to the unnamed module, which conflicts with the same package being included in the Java's most recent versions, with its own module name.

    That said, the practical solution is essentially to work with Maven exclusions to remove those dependencies from your project and let it use the JDK version instead. Use the equivalent if you're working with another build system. In theory, the JDK recent version might be non backward-compatible, in practice I doubt such JSR specifications changed much over the years and so far I haven't seen any issue with their replacement.

提交回复
热议问题