Include Azure Service Bus

Enonic version: 7.10


I’m trying to include Azure Service Bus in a project and eventually I stumbled here: Azure Service Bus SDK for Java | Microsoft Learn.
After including it in build.gradle (as in here) I noticed I can build and deploy the app, but the build crashes in our pipeline.

Captura de tela de 2023-01-30 14-47-18

I tried also with “include” (and “compile”), which finished building the app, but gives “java.lang.NoClassDefFoundError: com/azure/messaging/servicebus/ServiceBusClientBuilder”.

The java file I implemented is based on azure-sdk-for-java/ at main · Azure/azure-sdk-for-java · GitHub.

Does anyone know why I may be getting these errors?

I’m also considering using the npm package, but I’m not sure how to include it in an Enonic project (with or without react4xp).

I’m using the webpack starter for most of my projects. It lets me use npm-packages and TypeScript.

1 Like

I took a reading this weekend and indeed it seems that can be helpful. Probably because I’m new at it, but I had a hard time trying to get it all to work as it has async/await. I still didn’t manage to do it, so perhaps I’ll set up a conventional webpack piece only to bundle the module :crossed_fingers:

Did you manage to get a module with promises working as well?

No. Unfortionatly it’s not trivial to get Promises working in XP since it runs JavaScript on the Nashorn engine (where Promise is not supported).

You might be able to polyfill Promises, but I think it’s risky to go down that road.

If I were you, I would instead try to get the Java SDK working, and create a thin JavaScript-wrapper to interact with it.

If you haven’t used Java from JavaScript before, these are some of the functions you can use.

I also like to use Java.type to in JavaScript/TypeScript to grab a Java-class, and use it.


const LocalDateTime = Java.type<LocalDateTime>("java.time.LocalDateTime");

interface LocalDateTime {
  parse(text: string): LocalDateTime;
  format(formatter: DateTimeFormatter): string;

const myTime = LocalDateTime.parse("2011-12-03T10:15:30");

– Tom Arild

1 Like

Ah, yes. Using Java was, in fact, my first shot. I was having some issues with it, though, but perhaps I’m just missing something.
I’m following the Microsoft’s example for sending a messages batch and the suggestion for gradle, with “implementations”. The issue is that I then get a “java.lang.NoClassDefFoundError”. Using include I get a build error.

Captura de tela de 2023-02-07 08-38-44

The exception:
Captura de tela de 2023-02-07 08-40-43

And in Java:

Marco Thome

I did the following in the webpack starter:

dependencies {
  include ''
  include ''

And it builds fine with enonic project build.

It is probably include you want to use, so that the class-files get included in your buildt jar-file.

– Tom Arild

This is odd. Using include (I’m now using the starter-lib as a start point) only gives me the following:

Captura de tela de 2023-02-07 11-04-25

Edit: It did just work with the webpack-starter and include as well :man_shrugging: so I’ll just try to strip the extra functionalities and use like it is

There is a difference between applications and libraries. They have different build plugins in Gradle ("" and "com.enonic.xp.base").

If you tried using the library starter, then "com.enonic.xp.base" would not support include on dependencies.

– Tom Arild

1 Like