无法找到安装我自己的 snap 的“主类”

无法找到安装我自己的 snap 的“主类”

几天前我开始使用 Ubuntu Core 和 Snaps。我已经完成了最基础的教程关于创建我自己的快照,一切都很完美。

现在是时候更进一步了,因此出于更大的目的,我尝试创建自己的 Hello World 快照。我的想法是编写一个 Java 守护进程,用于从右到左打印“hello world”,使用 StringUtils 库只是为了添加一些 maven 依赖项,并从 GitLab 私有存储库下载代码。

Java 代码在我的计算机上运行良好,因此我选择了 snapcraft.yaml:

name: java-maven-hello
version: 0
summary: A java example using maven dependecies
description: this is not much more than an example
confinement: devmode
grade: devel

apps:
  daemon:
    command: java -cp basic-project-0.0.1-SNAPSHOT.jar es.ramadorp.odm.snapcraft.test.daemon.Daemontest
    restart-condition: always 
    daemon: forking

parts:
  daemon:
    plugin: maven
    source: http://gitlab.ramadorp.es/ramador/snap-maven-test.git

运行 snapcraft 的时间到了,到目前为止还没有问题,但是当我尝试安装已交付的 snap 时,我得到了:

error: cannot perform the following tasks:
- Start snap "java-maven-hello" (unset) services ([start snap.java-maven-hello.daemon.service] failed with exit status 1: Job for snap.java-maven-hello.daemon.service failed because the control process exited with error code.

“systemctl status snap.java-maven-hello.daemon.service”给我:

● snap.java-maven-hello.daemon.service
   Loaded: not-found (Reason: No such file or directory)
   Active: failed (Result: timeout) since lun 2017-04-24 10:23:54 CEST; 4min 34s ago

abr 24 10:22:24 Bec systemd[1]: Starting Service for snap application java-maven-hello.daemon...
abr 24 10:22:24 Bec /usr/bin/snap[8670]: cmd.go:111: DEBUG: restarting into "/snap/core/current/usr/bin/snap"
abr 24 10:22:24 Bec snap[8670]: Error: Could not find or load main class es.ramadorp.odm.snapcraft.test.daemon.Daemontest
abr 24 10:22:24 Bec systemd[1]: snap.java-maven-hello.daemon.service: Control process exited, code=exited status=1
abr 24 10:23:54 Bec systemd[1]: snap.java-maven-hello.daemon.service: Start operation timed out. Terminating.
abr 24 10:23:54 Bec systemd[1]: Failed to start snap.java-maven-hello.daemon.service.
abr 24 10:23:54 Bec systemd[1]: snap.java-maven-hello.daemon.service: Unit entered failed state.
abr 24 10:23:54 Bec systemd[1]: snap.java-maven-hello.daemon.service: Failed with result 'timeout'.

因此,我理解安装没有找到.jar要执行的?,但我深入研究了 snapcraft 创建的文件夹,发现那里"basic-project-0.0.1-SNAPSHOT.jar"/home/bec_1/wkf/snapmaven/parts/daemon/build/target。我所掌握的知识不足以理解 .jar 位置是否正确或安装为什么找不到“主类”。有什么想法吗?顺便说一下,我的pom.xml文件如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.boundedinfinity</groupId>
    <artifactId>basic-project</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
        </dependency>
    </dependencies>

</project> 

答案1

启动时,您可能需要指定 jar 文件的路径。如下所示:

    command: java -cp $SNAP/basic-project-0.0.1-SNAPSHOT.jar es.ramadorp.odm.snapcraft.test.daemon.Daemontest

相关内容