Printing from a java application

When I try to print from a java application I get this error message:

Caused by: Cannot run program "/usr/bin/lpr": error=2, No such file or directory
        at java.lang.ProcessBuilder.start(

I added cups-bsd to the snap and lpr is availalble in $SNAP/usr/bin/lpr.
But in the JDK in the path of lpr is hardcoded and expected to be /usr/bin/lpr
(from in openjdk 11)

1621         String osname = System.getProperty("");
1622         if (osname.equals("Linux") || osname.contains("OS X")) {
1623             execCmd = new String[ncomps];
1624             execCmd[n++] = "/usr/bin/lpr";

Is there a way to make lpr available as /usr/bin/lpr inside the snap?

The layout feature should be able to help you with this: Layouts: re-mapping snap directories. The feature is new, currently behind a feature flag and that page doesn’t mention using layouts with files, but it supports them. If you have trouble with the feature, talk to @zyga-snapd.

@zyga-snapd - I can’t find a ‘doc’ page on layouts-- is there a topic where its use is fully described?

There isn’t one yet. I think I should convert the existing one.

1 Like

Have you found a way to print from java inside snap? My application works without any issues printing with DEB, RPM and even flatpak I just can’t get it to print in snap.

Looking forward to your reply and solution :slight_smile: