Overview: Maven in TIBCO Streaming

Overview: Maven in TIBCO Streaming

book

Article ID: KB0071475

calendar_today

Updated On:

Products Versions
TIBCO Streaming 10.6 and later

Description

This article describes the general use of Apache Maven in TIBCO Streaming for managing builds.

Issue/Introduction

The general use of Maven in TIBCO Streaming for managing builds

Resolution

Building Streaming Fragments and Applications

In SB Studio, right-click a project in the Project Explorer and choose menu: Run As > Maven Build..., and in the dialog set Goals "clean install" and setting "Skip Tests" as needed. 

Maven Build dialog with Goals and Skip Tests set
The Name may appear as "project_name (1)", indicating there is already a run configuration with that name. You may change that to "project_name build" or some other useful differentiator so later you can just pick this build action from the Run Menu without having to revisit the dialog. Click Apply (if you made changes) and Run to start the build.

An EventFlow, LiveView, or Java fragment project builds to a fragment ZIP in the project target/ folder. An Application project usually builds to an application ZIP in the project target/ folder, but if it is configured for Docker (optionally with Kubernetes or Helm) it will build to a larger directory structure and the container image will be placed in the local container repository. The fragment or application ZIP is also placed in the local Maven Repository for use as a dependency to other projects.

For Application projects, if "Skip Tests" is NOT selected, then after the build succeeds one or more nodes will be launched on the local system based on the pom.xml setting for <nodes> within the ep-maven-plugin build configuration. We advise there be a single node (typically named 'A') here so that only one node is started for unit tests. All JUnit tests found in the project src/test/resources folder for all included fragments will be run and if any fail the build will report as having failed, no archive will be built, and the node directory will be preserved under the project target/test-nodes/ folder for analysis. 

Running even simple tests will add some time to the build, so it is recommended that the build is separated from tests by running tests separately using project menu: Run As > JUnit Test.

The same build may be performed by opening a StreamBase Command Prompt (or shell configured with the Streaming environment), changing the active directory to a project root folder (the directory with the pom.xml file in it), and running:
  mvn clean install
 

Local Maven Repository

On any development or build system Maven creates a hierarchy of directories for libraries and artifact files used as dependencies. The user local repository is found at:

  • Windows: C:\Users\name\.m2\repository
  • Linux: /home/name/.m2/repository
  • Mac: /Users/name/.m2/repository

Build dependencies are first resolved from the user local repository, and if not found there, then (by default) from Maven Central (https://repo.maven.apache.org/maven2/). When a library is found it is copied into the user local repository from the external remote repository for future use.

Streaming 10+ loads all libraries included in its install into the user local repository when SB Studio is opened in a new workspace. Any expected libraries which are not already present are copied in the background as Studio starts. Since this activity may take a few minutes we recommend you open the Eclipse "Progress" view. Build and typechecking activity will be incomplete until after this process is complete. If the local repository is already populated, then this process completes quickly. You may manually install the Streaming libraries into the local or a remote repository using the command 'epdev install maven’ from the StreamBase Command Prompt or a configured shell.

Any time a requested dependency is unavailable, a placeholder record is created in that location in the repository and the missing files will be identified by a filename.lastUpdated file. If this placeholder file and the actual library file are both in the repository folder, then the presence of the filename.lastUpdated file may block indexing and dependency resolution until it is removed. Once you have ensured the needed artifact is available from a configured repository, refresh the project by right-clicking it in the Project Explorer and choosing menu item: Maven > Update… . In the dialog set the "Force Update of Snapshots/Releases" option and click OK. This is equivalent to the 'mvn’ command-line parameter '--force’ when performing a build action.

Updating the repository after a failure to download artifacts
In Streaming 10+ the Eclipse Build Path is ignored and libraries should be referenced from their appropriate Maven Central repository location in the pom.xml as a dependency entry, for example:

 <dependency>   <groupId>postgresql</groupId>   <artifactId>postgresql</artifactId>   <version>9.1-901.jdbc4</version> </dependency>
Any libraries not directly downloadable from Maven Central (the vendor has not provided the library publicly) may be uploaded into the local repository using the ' install' Maven command (split across multiple lines for clarity):
 mvn install:install-file  \ -Dfile=path-to-file       \ -DgroupId=group-id        \ -DartifactId=artifact-id  \ -Dversion=version         \ -Dpackaging=jar -DgeneratePom=true
For example, the above dependency may be installed manually using this command:
 mvn install:install-file    \ -Dfile=./postgresql9.1.jar  \ -DgroupId=postgresql        \ -DartifactId=postgresql     \ -Dversion=9.1-901.jdbc4     \ -Dpackaging=jar -DgeneratePom=true

For reference, see: Please take care when manually installing libraries that you use the vendor preferred groupId, artifactId, and version, since modifying these is allowed but will lead to additional maintenance work and conflicts.

Mirrors, Proxies, and settings.xml

The set of repositories searched for dependencies is configured by the optional settings.xml file placed in each user’s local .m2/ folder. A settings.xml file with examples and additional configuration guidance is available in your TIBCO Streaming install folder:
  sdk/mvn/conf/settings.xml
If you do not currently have a settings.xml file and are only using the Maven defaults, you may copy this sample file into your .m2/ folder and customize it as needed to identify mirror repositories and proxy settings.

Your company may have a shared repository, as described here:  https://maven.apache.org/repository-management.html
The shared repository may be used alongside Maven Central, or replace it in your development environment as a mirror.

Several examples are:  

Repository Maintenance

Shared repositories are maintained by their administrators. The Streaming libraries may be uploaded from a single user install to your team or corporate repository using command:

epdev deploy maven <destination path or URL>

The user local repository tends to accumulate library versions over time. This may become a disk-space concern. You may remove libraries using commands:

  • epdev clean mavenremove TIBCO EP artifacts from the local repository, all versions
  • epdev clean-tibco mavenremove all TIBCO artifacts (all products) from the local repository
  • epdev clean-all mavenremove ALL artifacts from the local repository

Your working set of libraries may then be restored by performing a build of the active projects, which will re-download the libraries available from the repositories referenced by your settings.xml configuration. Note that any libraries unavailable from repositories will need to be manually installed using the 'mvn install:install-file' command.
 

Versioned Product Artifacts and Hotfixes

POM (pom.xml) dependencies specify a specific version of a library or resource. Streaming SB Studio manages dependencies to platform and adapter libraries and will update the POM or offer to update the POM when a project that references a different version of Streaming is imported into the workspace.

3rd-party, other TIBCO products, and Engineering Build or Hotfix libraries are not managed. Use of a different version requires changing the pom.xml dependency. Streaming adapter hotfixes are often delivered as a single JAR file with instructions to use command-line 'mvn’ to place the file into the local repository. The command typically looks like this:

 mvn install:install-file -Dfile=bloomberg-blpapi-10.6.3-hf1.jar \ -DgroupId=com.tibco.ep.sb.adapter -DartifactId=bloomberg-blpapi \ -Dversion=10.6.3-hf1 -Dpackaging=jar -DgeneratePom=true

To reference the new library in the project POM, use a dependency like this:
 <dependency>   <groupId>com.tibco.ep.sb.adapter</groupId>   <artifactId>bloomberg-blpapi</artifactId>   <version>10.6.3-hf1</version> </dependency>

To revert to the original version, change the <version> value as needed, for example, back to "10.6.3".