gpt4 book ai didi

java - Java 10 上的 Swing 问题

转载 作者:行者123 更新时间:2023-12-02 11:20:23 25 4
gpt4 key购买 nike

我目前正在尝试将我们的应用程序从 Java 8 迁移到 Java 10,几个月后将迁移到 Java 11。

我们有一个旧系统,它使用了一些 API,我猜这些 API 已被删除或将被删除。我们使用 ant 脚本 (1.10.1) 来编译应用程序。

以下是构建我们的应用程序的相同部分:

  <target name="javac-setup" depends="flags, with.clover, jaxb-apply, flamingo.javac"/>

<target name="javac" depends="javac-setup">
<mkdir dir="${workmanager.dir.classes}"/>
<javac destdir="${workmanager.dir.classes}" deprecation="on" debug="${javac.debug}" encoding="iso-8859-1" includeantruntime="false">
<compilerarg line="-Xlint:static"/>
<compilerarg line="-Xlint:unchecked"/>
<compilerarg line="-Xlint:overrides"/>
<compilerarg line="-Xmaxerrs 9999" />
<compilerarg line="-Xmaxwarns 9999" />
<compilerarg value="-Werror"/>
<src path="${workmanager.dir.src}"/>
<src path="${webservices.dir.java.src}"/>
<patternset refid="java.sources"/>
<classpath refid="classes.classpath"/>
</javac>
</target>

在迁移到 Java 10 后,在编译过程中,我遇到了一些与 Java Swing 相关的错误(又是一个较旧的错误,但必须忍受它)。由于我仍然不完全了解 Java 10 中发生的所有更改,因此在我看来,这个问题与模块化概念有关。虽然还在学习但不确定。我知道您的建议是了解此类错误是否与模块化有关。还有解决这些问题的建议或技巧吗?

下面是错误:

[javac] Compiling 3253 source files to C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\classes
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\datamgmt\report\ui\AssignPosNumberToolbar.java:26: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsButtonUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\datamgmt\report\ui\AssignPosNumberToolbar.java:27: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsToolBarUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\utils\WMClosableTabbedPane.java:33: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsTabbedPaneUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\MultiColumnComboBox.java:58: error: package com.sun.java.swing.plaf.motif is not visible
[javac] import com.sun.java.swing.plaf.motif.MotifComboBoxUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.motif is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\datamgmt\ui\SimplificationComboBox.java:31: error: package com.sun.java.swing.plaf.motif is not visible
[javac] import com.sun.java.swing.plaf.motif.MotifComboBoxUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.motif is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\xplookandfeel\XPComboBoxUI.java:21: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsComboBoxUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\datamgmt\ui\favorites\FavoritesToolBar.java:28: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsButtonUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\datamgmt\ui\favorites\FavoritesToolBar.java:29: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsToolBarUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\ptc\PtcLaf.java:14: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\ptc\PtcMenuUI.java:31: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\ptc\PtcRadioButtonMenuItemUI.java:14: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsIconFactory;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\ptc\PtcSeparatorUI.java:20: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsSeparatorUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\xplookandfeel\XPButtonUI.java:26: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsButtonUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\xplookandfeel\XPLookAndFeel.java:24: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsIconFactory;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\xplookandfeel\XPLookAndFeel.java:25: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\xplookandfeel\XPMenuUI.java:25: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\xplookandfeel\XPRadioButtonMenuItemUI.java:14: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsIconFactory;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\xplookandfeel\XPSeparatorUI.java:17: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsSeparatorUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\xplookandfeel\XPToggleButtonUI.java:23: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsToggleButtonUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] C:\WorkSpace\JAVA10\oswm\rel20.10_Patches\WorkManager\src\com\osm\ui\laf\xplookandfeel\XPToolBarUI.java:17: error: package com.sun.java.swing.plaf.windows is not visible
[javac] import com.sun.java.swing.plaf.windows.WindowsToolBarUI;
[javac] ^
[javac] (package com.sun.java.swing.plaf.windows is declared in module java.desktop, which does not export it)
[javac] 20 errors

最佳答案

是的,这是由于模块系统造成的。您是accessing internal APIs ,JPMS 默认不允许您这样做。

快速修复

要快速修复此问题,请使用 the command line option --add-exports %module/%package=ALL-UNNAMED对于消息提到的每个包,例如:

--add-exports java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED

(不,没有通配符)您必须将这些添加到 Java 9+ 的构建命令中,并在某些时候(可能是 Java 12+)也添加到执行命令中。

正确修复

如前所述,这只是一个快速修复。模块系统就位后,JDK 团队可能会更积极地重构内部结构,例如您正在使用的 API,因此您将来很可能会遇到更改或删除类的问题。

正确的解决方法是消除对这些内部组件的依赖。第一步是检查您正在使用的功能是否同时已获得标准化 API。

关于java - Java 10 上的 Swing 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51555030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com