首页 > 解决方案 > snapscraft snap.yaml 用于在 ubuntu 上使用 swing ui 的 Java 应用程序

问题描述

我有一个使用 java.awt Swing UI 的基本 java 应用程序,我想为它创建一个 snap,所以当它安装时,有一个可用的启动器和我的 UI 启动。我使用 gradle 和 jar 任务来创建一个可以正常工作的 jar。

自然地,我在一个类中,当调用时加载我的应用程序就好了:

    package com.foo
    class Bar() {
         static void main(String... args) { launchUI() }
    }

我在项目的根目录创建了一个 snap 文件夹和一个 snap.yaml,我按照https://snapcraft.io/docs/java-applications上的说明创建了一个 snap yaml,它可以生成一个 snap 文件,该文件也可以正常安装:

name: deepthought
base: core18  
version: '0.0.7'
summary: ""
icon: gui/foo.png
description: |
 Computes the ultimate answer for life the universe and everything

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

# This doesn't work
#apps:
#  htmldoc:
#    command: desktop-launch $SNAP/bin/foo.sh
##    desktop: share/applications/htmldoc.desktop
#    plugs: [home, network, x11]
parts:
  foopart:
    plugin: gradle
    source: https://github.com/bsautner/foo.git
    source-type: git
    gradle-options: []   # suppress running of tests and run the war task
    gradle-output-dir: build/libs

我花了很长时间试图弄清楚:

I'd really appreciate if anyone can share a working snap.yaml for a java program with a launcher and if there is any mention of a path to something that you note where those files are in relation to the path of the /snap/snap.yaml file

标签: javaubuntusnapcraft

解决方案


ok figured it out - the docs don't say this but the files are relative to the root of the project so even though the yaml says this is the launch

apps:
  cmd3:
    command: usr/bin/foo.sh

foo.sh should be in the root of the project and the orginize section here moves it to the bin dir

  foo:
    plugin: gradle
    source-type: local
    source: .
    build-packages:
      - openjdk-11-jdk
    stage-packages:
      - openjdk-11-jdk
      - x11-utils
    organize:
      ${SNAPCRAFT_PART_BUILD}/jg-snap: usr/bin/foo.sh

The jar is in the /snap/foo/current/usr/jar directory


推荐阅读