Java(Swing 和 AWT)应用程序的 Snap 包在执行时崩溃

Java(Swing 和 AWT)应用程序的 Snap 包在执行时崩溃

我正在尝试为 Java(Swing 和 AWT)应用程序构建一个 snap 包。它允许自动从互联网下载(和管理)壁纸并将其存储在本地。这是snapcraft.yaml文件:

name: wallpaperdownloader
version: 2.0
summary: Download and manage your favorite wallpapers fron the Internet
description:
  Wallpaperdownloader is a simple java based application for downloading wallpapers from the Internet
confinement: strict
apps:
  wallpaperdownloader:
    command: java -jar $SNAP/jar/wallpaperdownloader.jar
    plugs: [x11, network-bind]
parts:
  wallpaperdownloader:
    plugin: maven
    source: https://bitbucket.org/eloy_garcia_pca/wallpaperdownloader.git
    source-type: git

我毫无问题地构建了它(使用 Maven 插件),并创建了 snap 包。然后我使用以下命令安装它:--开发模式标志以绕过限制(仅用于测试目的),但它不起作用。它创建了一个.wallpaperdownloader文件夹内/主页/用户包含运行所需的所有东西和配置,但它在出现任何 GUI 之前就崩溃了。这是抛出的异常:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
    at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
    at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
    at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
    at sun.font.SunFontManager$2.run(SunFontManager.java:431)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.font.SunFontManager.<init>(SunFontManager.java:376)
    at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
    at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
    at sun.font.SunFontManager.getInstance(SunFontManager.java:250)
    at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264)
    at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1113)
    at javax.swing.JComponent.getFontMetrics(JComponent.java:1626)
    at javax.swing.text.PlainView.calculateLongestLine(PlainView.java:639)
    at javax.swing.text.PlainView.updateMetrics(PlainView.java:209)
    at javax.swing.text.PlainView.updateDamage(PlainView.java:527)
    at javax.swing.text.PlainView.insertUpdate(PlainView.java:451)
    at javax.swing.text.FieldView.insertUpdate(FieldView.java:293)
    at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1610)
    at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1869)
    at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:201)
    at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:748)
    at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:707)
    at javax.swing.text.PlainDocument.insertString(PlainDocument.java:130)
    at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:669)
    at javax.swing.text.JTextComponent.setText(JTextComponent.java:1669)
    at javax.swing.JFormattedTextField$AbstractFormatter.install(JFormattedTextField.java:948)
    at javax.swing.text.DefaultFormatter.install(DefaultFormatter.java:125)
    at javax.swing.text.InternationalFormatter.install(InternationalFormatter.java:285)
    at javax.swing.JFormattedTextField.setFormatter(JFormattedTextField.java:464)
    at javax.swing.JFormattedTextField.setValue(JFormattedTextField.java:788)
    at javax.swing.JFormattedTextField.setValue(JFormattedTextField.java:501)
    at es.estoes.wallpaperDownloader.window.WallpaperDownloader.initializeGUI(WallpaperDownloader.java:814)
    at es.estoes.wallpaperDownloader.window.WallpaperDownloader.initialize(WallpaperDownloader.java:426)
    at es.estoes.wallpaperDownloader.window.WallpaperDownloader.<init>(WallpaperDownloader.java:160)
    at es.estoes.wallpaperDownloader.window.WallpaperDownloader$1.run(WallpaperDownloader.java:149)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

非常感谢您的帮助。

答案1

替换命令:

java -jar $SNAP/jar/wallpaperdownloader.jar

run.sh

这是run.sh

#!/bin/sh
# Not good, needed for fontconfig
export XDG_DATA_HOME=$SNAP/usr/share
# Font Config
export FONTCONFIG_PATH=$SNAP/etc/fonts/config.d
export FONTCONFIG_FILE=$SNAP/etc/fonts/fonts.conf
export HOME=$SNAP_USER_DATA
java -jar -Duser.home=$SNAP_USER_DATA $SNAP/jar/wallpaperdownloader.jar

"-Duser.home=$SNAP_USER_DATA" 解决了我的问题。

更新:查看完整示例在 Snappy Playpen 中使用自定义启动器进行启动。

相关内容