Skip to content

Martini Services Using JAR Files

Usage

Integrating third-party functionalities into your Martini applications through JAR files or extension modules enhances your application's capabilities. This section details how to utilize the extension methods and services provided by the imported JAR files within your Martini package.

Preparing Your Package

Ensure the JAR or extension module descriptor file is correctly placed under your Martini package's META-INF/services directory. This setup is crucial for Martini to recognize and utilize the functionalities provided by the JAR.

Using Extension Methods

Extension methods augment the existing classes with new functionalities without modifying their source code. You can use these methods directly on instances or as static methods.

Instance Extension Methods

Instance extension methods allow you to call new methods on existing class instances as if they were defined within the class itself. For example:

1
2
3
4
5
// To use an instance extension method
144.gcf(32) // Calls the `gcf` method on the integer 144 with 32 as an argument

// Another example using a list
[144, 64, 32].gcf() // Calls the `gcf` method on the list instance

Static Extension Methods

Static extension methods are invoked on the class itself rather than an instance. These methods are typically utility functions that do not require an instance of the class to work. For example:

1
2
// To use a static extension method
ClassName.method(arguments...)

Replace ClassName with the class name, method with the static method name, and arguments... with the required arguments for the method.

Invoking Services from Your JAR

The JAR file can contain services or methods you wish to invoke within your Martini application. These services are accessible as:

  • Public Static Methods: These methods can be invoked without creating an instance of the class. They are often used for utility or helper functions.

  • Public Instance Methods: These methods require an instance of the class to be created. The class must have a public nullary (no-argument) constructor to be invocable.

To invoke a service or method from your JAR, navigate to the desired service (or method) and follow the standard Java invocation patterns, depending on whether the method is static or instance-based.