java - 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
我花了很长时间试图弄清楚:
- 如果我创建一个 shell 脚本来运行 java -jar foo.jar 命令,它会在 /snap 目录中结束,但它不在用户路径上,所以他们无法访问它
- 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
解决方案
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
推荐阅读
- java - 主键重复时 JavaEE 不抛出 SQLException
- html - datalist 中的文本是可选的,值可以替换吗?
- reactjs - 没有提供模板。这可能是因为您使用的是过时版本的 create-react-app
- c++ - 如何将二叉树转换为二叉决策图
- powershell - 无法为每个循环获取写入进度
- scope - 存在于 where 外部范围内的值的“未定义名称”
- android - 如何在颤振上解决这个小部件问题?
- raku - 使用 Raku 的 Code.sumption 方法和使用匿名 Block 或 Sub 有什么区别?
- swift - 真的可以在 Swift 中独立于 AV 源进行 AV 处理吗?
- typescript - TypeScript 此表达式不可调用