hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
185 stars 73 forks source link

Session transports not found in uber-jar #194

Closed dvogel closed 1 year ago

dvogel commented 1 year ago

I'm receiving this error:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.freedesktop.dbus.connections.impl.DBusConnectionBuilder.validateTransportAddress(DBusConnectionBuilder.java:129)
    at org.freedesktop.dbus.connections.impl.DBusConnectionBuilder.forSessionBus(DBusConnectionBuilder.java:43)
    at org.freedesktop.dbus.connections.impl.DBusConnectionBuilder.forSessionBus(DBusConnectionBuilder.java:65)
    at dim.plantuml.PlantUmlHelper.sendViaDbus(PlantUmlHelper.java:100)
    at dim.plantuml.PlantUmlHelper.main(PlantUmlHelper.java:141)
Caused by: org.freedesktop.dbus.exceptions.TransportRegistrationException: No dbus-java-transport found in classpath, please add a transport module
    at org.freedesktop.dbus.connections.transports.TransportBuilder.getTransportProvider(TransportBuilder.java:63)
    at org.freedesktop.dbus.connections.transports.TransportBuilder.<clinit>(TransportBuilder.java:35)
    ... 5 more

I would expect the unix transport to be found and used because my environment has:

DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

And my uber-jar contains:

unzip -l plantuml-helper.jar | grep transport
        0  2022-09-08 14:50   org/freedesktop/dbus/connections/transports/
     7690  2022-09-08 14:50   org/freedesktop/dbus/connections/transports/AbstractTransport.class
      644  2022-09-08 14:50   org/freedesktop/dbus/connections/transports/AbstractUnixTransport.class
      374  2022-09-08 14:50   org/freedesktop/dbus/connections/transports/IFileBasedBusAddress.class
     1760  2022-09-08 14:50   org/freedesktop/dbus/connections/transports/TransportBuilder$SaslAuthMode.class
    12902  2022-09-08 14:50   org/freedesktop/dbus/connections/transports/TransportBuilder.class
        0  2022-09-08 14:50   org/freedesktop/dbus/spi/transport/
     1352  2022-09-08 14:50   org/freedesktop/dbus/spi/transport/ITransportProvider.class
        0  2022-10-31 22:47   org/freedesktop/dbus/transport/
        0  2022-09-08 14:51   org/freedesktop/dbus/transport/jre/
     1775  2022-09-08 14:51   org/freedesktop/dbus/transport/jre/NativeTransportProvider.class
     1170  2022-09-08 14:51   org/freedesktop/dbus/transport/jre/NativeUnixSocketHelper.class
     3251  2022-09-08 14:51   org/freedesktop/dbus/transport/jre/NativeUnixSocketTransport.class
     1702  2022-09-08 14:51   org/freedesktop/dbus/transport/jre/UnixBusAddress.class
        0  2022-09-08 14:50   org/freedesktop/dbus/transport/tcp/
     1331  2022-09-08 14:50   org/freedesktop/dbus/transport/tcp/TcpBusAddress.class
     3102  2022-09-08 14:50   org/freedesktop/dbus/transport/tcp/TcpTransport.class
     3418  2022-09-08 14:50   org/freedesktop/dbus/transport/tcp/TcpTransportProvider.class

This is using java 17:

java -version
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment (build 17.0.4+8-Debian-1)
OpenJDK 64-Bit Server VM (build 17.0.4+8-Debian-1, mixed mode, sharing)
dvogel commented 1 year ago

The uber-jar did indeed include the transports but the META-INF/services/org.freedesktop.dbus.spi.transport.ITransportProvider was missing. This is working for me now.

These messages mentioning the classpath could mention the ServiceLoader docs instead of or in addition to the classpath for easier debugging.

jnsw commented 1 year ago

The uber-jar did indeed include the transports but the META-INF/services/org.freedesktop.dbus.spi.transport.ITransportProvider was missing. This is working for me now.

where is this missing?

EDIT: isnt it this? Bildschirm­foto 2022-11-25 um 10 35 41

hypfvieh commented 1 year ago

The described problem here was, that creating an ueber-jar using maven shade or assembly plugin, you may have to define to include the META-INF/services/org.freedesktop.dbus.spi.transport.ITransportProvider in the ueber jar as well.

Otherwise the plugins will include the java classes, but not the service loader definition file required when using dbus-java from class path instead of module path.

jnsw commented 1 year ago

thank you!