Snap from .jar

Its working now… I simply add the desktop interface in the plugs…

It sounds like you have a complete Java snap package currently working! :blush:

@eloy.garcia.pca

Yes…:blush::blush:

@eloy.garcia.pca

I learnt small things in snap… I want to know more about it…
So I am expecting your help more on future… Can You help me???

My knowledge in snaps is very limited (I only have one snap package published) but this is the place to learn a lot around this great packaging technology. There are a lot of wise people very committed with it.

On the other hand, if I can help I’ll do my best too :wink:

Cheers!

1 Like

@eloy.garcia.pca

OK, Thanks…Man…:blush::blush:

How to read the properties file that pulled inside in the snap file, by the java code?

The path that gives inside in the java code read local files ex: home/source/file_name
I want to give the path like $SNAP/.
Now how to change that path to read the files inside in the zipped snap file?
But I don’t know to make that…

Hey @Siva you can in java access the Environment Variables like so:

System.getenv(“SNAP_USER_COMMON”)

here is an overview of the ENV in Snaps when there running:

https://docs.snapcraft.io/reference/env

Greets

@tokurz

Okay… I will try that…

@tokurz

Hi tokurz, from this , How I need to use the SNAP_USER_DATA and SNAP_USER_COMMON in my java source code.
Can you give me some examples for this…

Is it possible to put the env in snapcraft.yaml or it in .sh file???

I tried this in my snapcraft.yaml file part…

environment:
JAVA_HOME: $SNAP/usr/lib/jvm/default-java
CLASSPATH: $SNAP/jar/SnapTest.jar
SNAP_USER_DATA: $SNAP/src/conf/database.properties
SNAP_USER_COMMON: $SNAP/src/conf/database.properties
PATH: $SNAP/usr/lib/jvm/default-java/bin:$PATH

But it didn’t work… It could not read the database.properties file…
Is it correct or am I need to change anything in this part???..

Tip, use triple back tics (```) to format code samples, otherwise spacing is lost and the code may become meaningless.

1 Like

@Siva you can also use like $SNAP in your java code to read values there, but like $SNAP_HOME or $SNAP_USER_COMMON will be create in the home directory from the user where it will be running.

the Path: $SNAP is read only folder, How you build your java Project? Gradle,Maven?

May you should also create a kind of wrapper file where contains some env,like

export JAVA_HOME=$SNAP\usr\lib\jvm\default-java
java $SNAP/bin/my.jar -cp $SNAP/javalib-classpath

name: myexampleservice
version: 1
summary: My Example Service
description: My example Service
confinement: strict
grade: devel
architectures: [armhf]
apps:
 myservice:
  command: install/bin/GradleWrapperGeneratedFile
  daemon: simple
  restart-condition: always
  slots: [myslotshere]
  plugs: [myplugshere]
slots:
 myslotshere:
  ....
plugs:
 myplugshere:
  .....
parts:
 copyexample:
  source: install/
  plugin: dump
  organize:
   '*' : install/

I want to have this conf/database.properties file for all my revisions, so i plan to set the environment variable and tried to execute the command
snap run --shell snap.hello-world.env
but getting the error error: cannot find current revision for snap snap: readlink /snap/snap/current: no such file or directory. Please help me how to make the snap read the conf file.

Note : In my application i am trying to read the file to get the database username, password and ip.

Hi Siva.

I have a snap package published in the store and it is a Java application.
The code is published on Bitbucket. This is the link, so you can check the
snapcraft.yaml file and the rest of the structure. I hope this helps!!

https://bitbucket.org/eloy_garcia_pca/wallpaperdownloader/src/master/snap/

Cheers.

@eloy.garcia.pca

Ok… Eloy I try this…

Anyone please tel me how to use serial-port interface in snap.
If there is any example, it would be nice…

Hey @Siva , which kind of serial-port for Which device?

Here is an similiar topic with serial-port

https://forum.snapcraft.io/t/cannot-open-dev-ttys4/1623

Greets Tony

Hi @tokurz
Sorry for not replying… I solved this problem.
I used java snap application for Ubuntu core. The device is 4-port Serial USB device.

My tomcat snapcraft.yaml is

apps:
snap:
command: usr/lib/jvm/jdk1.8.0_152/bin/java -Djava.library.path=$SNAPlib -jar
$SNAP/src/SampleTesting.jar
plugs: [wayland, desktop, network, home]
environment:
JAVA_HOME: $SNAP/usr/lib/jvm/default-java
CLASSPATH: $SNAP/jar/SampleTesting.jar
PATH: $SNAP/usr/lib/jvm/default-java/bin:$PATH

parts:
snap:
source: .
plugin: dump
organize:
jdk1.8.0_152 : usr/lib/jvm/jdk1.8.0_152
build-packages:
- ca-certificates
- ca-certificates-java