Skip to content

Package Properties in Martini

In Martini, you may find it useful to store certain values for later use in your services. One way to achieve this is through package properties.

Martini has different types of properties, which define how configurations are handled and can affect application behavior in various environments. For a detailed overview of the types and their hierarchy, please refer to the Types and Hierarchy of Martini Properties.

Types of Properties

Aside from explicit package properties packages inherit properties from the application properties, system properties, and environmental variables.

  1. Package Properties: These properties define variables specific to the application, such as API keys and endpoint URLs. They can be customized for each environment.

  2. Application Properties: These govern the overall behavior of your Martini applications, affecting essential settings like performance and functionality.

  3. System Properties: Exposed by the operating system, these properties can influence the runtime environment and overall stability.

  4. Environmental Variables: These control application behavior based on the environment (development, testing, production) in which it is running.

Hierarchy of Properties

The hierarchy of properties dictates the order in which different property files are processed, influencing which settings are applied:

  1. Package Environment Properties: Package properties specific to a particular environment that override default package properties.

  2. Package Properties: Properties specific to the Package being run.

  3. Application Override Properties: Application properties that allow overriding default application settings for specific scenarios.

  4. Application Properties: The standard application properties governing overall behavior.

  5. System Properties: Properties exposed by the system on which Martini is running.

  6. Environmental Variables: Variables that manage configurations based on the runtime environment.

Declaring Package Properties

Packages declare their properties under conf/properties:

1
2
3
├── conf
│   ├── properties
│   │   └── package.properties

The naming convention for properties can be modified by configuring the package.properties.prefix application property. For instance, if you set a package prefix of develop, the application will look for develop.package.properties instead of the default package.properties. This flexibility is useful for storing package properties for multiple environments or developers in one location—each installation can configure its own package.properties.prefix.

Like instance properties, any changes to your package properties will be visible immediately after saving the properties file (assuming the package.properties.reload-strategy application property is set to always-check).

Note: Your .properties files are not automatically generated when you create a package or change the value of package.properties.prefix. If your .properties files are missing, you must create them manually under the conf/properties folder.

Package Property Merging

Properties are merged according to package hierarchy. For example:

  • Package petclinic-demo depends on petclinic.
  • The petclinic package declares the following property:

    1
    petclinic.petstore-url=https://petstore.swagger.io
    

When accessing the property petclinic.petstore-url from the petclinic-demo package, the value https://petstore.swagger.io is resolved. This occurs because petclinic-demo depends on the petclinic package. If the dependency is removed, the property resolves to null.

The child package may declare a property with the same name, effectively overriding the parent property. For instance, if petclinic-demo declares the following property:

1
petclinic.petstore-url=http://localhost:5000

The resolved value for petclinic.petstore-url when accessed from the petclinic-demo package will now be http://localhost:5000.

Modifying Package Properties via Martini

To add or modify properties using the user interface, follow these steps:

  1. Navigate to the Navigator view.
  2. Locate your package and expand its contents by clicking on its node. Look for the conf directory.
  3. Double-click the .properties file to open it.
  4. Add, edit, or remove key-value pairs as needed.