“使用 Swing UI 在 Ubuntu 上为 Java 应用程序创建的 snapcraft snap.yaml”

huangapple go评论75阅读模式
英文:

snapscraft snap.yaml for java apps using swing ui on ubuntu

问题

以下是你要翻译的内容:

我有一个使用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文件的snap yaml文件,该文件也可以正常安装:

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
confinement: devmode

parts:
  foopart:
    plugin: gradle
    source: https://github.com/bsautner/foo.git
    source-type: git
    gradle-options: []
    gradle-output-dir: build/libs

我花了很多时间来尝试解决以下问题:

  • 如果我创建一个运行java -jar foo.jar命令的shell脚本,它会出现在/snap目录中,但它不在用户的路径中,因此他们无法找到它。
  • 我尝试创建启动器,但总是会出现找不到启动器的错误。如果我将其放在根目录下的/bin/launch.sh中,snap无法找到它。如果我将其放在snap/bin/文件夹中,我也会收到不要将文件放在snap文件夹中的错误。
  • 当我安装我的snap时,我看不到它放置我想要执行的jar文件,因此我无法编写执行它的脚本。

如果有人可以分享一个带有启动器的java程序的工作snap.yaml,并且如果有任何涉及路径的提及,请指出这些文件相对于/snap/snap.yaml文件的路径。

英文:

I have a basic java app using java.awt Swing UI and I want to create a snap for it so when it's installed there is a launcher available and my UI Launches. I use gradle and the jar task to create a jar which works fine.

Naturally I have in a class that when called loads my app just fine:

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

I created a snap folder at the root of the project and a snap.yaml where i followed the instructions on https://snapcraft.io/docs/java-applications so i have a snap yaml that produces a snap file which also installs fine:

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've spent quite some time trying to figure out:

  • If i create a shell script to run a java -jar foo.jar command it ends up in the /snap directory but it's not on the users path so they can't get to it
  • I've tried creating launchers but always get an error that my launcher can't be found, if i put it in my root folder as /bin/launch.sh snap can't find it and if i put it in the snap/bin/ folder i also get errors to not put things in the snap folder
  • When I do install my snap, i don't see where it puts my jar i want to execute, so i can't write a script that does that

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

答案1

得分: 0

了解了 - 文档没有提到这一点,但文件是相对于项目的根目录的,所以即使yaml文件中写着这个是启动项

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

foo.sh 应该位于项目的根目录,这里的 organize 部分将其移动到 bin 目录

  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

jar 文件位于 /snap/foo/current/usr/jar 目录下。

英文:

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

huangapple
  • 本文由 发表于 2020年10月3日 02:45:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/64176760.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定