How to make an internal Java package accessible in Eclipse?

淺唱寂寞╮ 提交于 2020-06-25 09:43:28

问题


I have a legacy Java (8) project opened in Eclipse with Java 11 (or Java 10). Eclipse is now rightly complaining about inaccessible packages. E.g. com.apple.laf.AquaComboBoxUI.

When compiling from command line I can make those packages accessible explicitly by adding a parameter to javac:

--add-exports java.desktop/com.apple.laf=ALL-UNNAMED

Is there a way to do the same from inside the Eclipse IDE? I tried to add an accessible rule on the JDK library. But that seems to have no effect. Any ideas?

And yes, I know, we should migrate the project to use only official APIs. But that's a long, long way...


回答1:


I'm answering my own question, since I found a solution.

  1. In Eclipse settings navigate to: Java Build PathLibrariesModulepathJRE System Library
  2. Expand it and double click on: Is modular (modifies encapsulation)
  3. Switch to Details tab
  4. Add a new export: E.g. java.desktopcom.apple.laf



回答2:


You need to setup problem severity. This falls under forbidden reference (access rules) under Java Compiler -> Errors/Warnings.




回答3:


As mentioned here you can add the parameters passed with javac in command line to Eclipse with these steps:

  • Click on Run->Run Configurations.

  • In the window that appeared under Main tab Browse the project and the Main class for which you want to pass the arguments.

  • Now click on the Arguments tab.
  • In the text-box labeled Program arguments:, type ${string_prompt}
  • Click on Apply and Close.

Now when you run your Java application a prompt will appear. You can add all your arguments separated with space here.



来源:https://stackoverflow.com/questions/52343704/how-to-make-an-internal-java-package-accessible-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!