Adding Libraries to a StreamBase Maven Project

Adding Libraries to a StreamBase Maven Project

book

Article ID: KB0074035

calendar_today

Updated On:

Products Versions
TIBCO Streaming 10

Description

TIBCO Streaming version 10.x uses Apache Maven based projects in StreamBase Studio which do not use the Eclipse project Build Path to reference libraries. Maven based projects use a pom.xml file to identify repositories, dependencies, and additional build configuration. 

To make a library available to the project these must be true:
  • the library is available in a referenced repository (local, Maven Central, or custom)
  • SB Studio must have a local index of that repository 
If these are true, then to add a library to your project as a dependency, do:
1. Right-click the top-level project folder in the Studio Package Explorer view and choose menu: Maven > Add Dependency
2. Search for the library by artifact name and select the library from the list of items returned and click Finish. Do this for each library to be added.

The pom.xml editor Dependencies tab in Studio also has an Add button which opens the same dialog to add dependencies.

If the library is not available, then see the following topics.

Issue/Introduction

In a StreamBase Maven-based project libraries on the project's Build Path are ignored. Instead every library needs to be loaded from a Maven Repository as a Maven Dependency.

Resolution

Repository Indexing

By default in StreamBase Studio, repository indexing is turned off, so libraries in local and remote repositories will not be found. To turn on indexing use menu: Window > Preferences, Maven, enable "Download repository index updates on startup", save the change and then restart SB Studio. The initial index update will take a few minutes. Subsequent updates will typically take a few seconds.

This can also be done from the Maven Repositories view in Studio, by right-clicking the desired repository and choosing Rebuild Index.
 

Using Maven Central

Most libraries are available from Maven Central, referenced in the StreamBase parent .pom as:
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </repository>

Your may wish to use other public Maven repositories as well. References to additional repositories may be placed in your project pom.xml file.
 

Using a Corporate Repository

In most development environments there will be a corporate "remote" Maven repository as described here:
  https://maven.apache.org/guides/introduction/introduction-to-repositories.html
and to use it add to the project pom.xml file an entry like this:
  <repositories>
    <repository>
      <id>my-internal-site</id>
      <url>http://myserver/repo</url>
    </repository>
  </repositories>

If you need to add libraries to your corporate repository you must have permission and the steps will be specific to your corporate environment and policies.

After making changes to your corporate repository, update your index in SB Studio, as described above.
 

Using a Local Repository

Before adding a library to your corporate repository you may want to work with it locally first. You may add library files to your private repository maintained on your system by Maven. These files will not be shared with other developers. Adding files to your private repository requires running the mvn command from the command-line. The mvn command is included with recent versions of TIBCO Streaming and is on the PATH when using the StreamBase Command Prompt environment.

As an example, the JMS Sample requires two library files from a TIBCO EMS install in order for the StreamBase JMS Operators to connect to an EMS server. Although the latest versions of these are available from Maven Central, you may wish to use  specific older versions which may be installed locally as follows.

From the command-line, when you are in the tibco\ems\8.2\lib directory, the Maven commands to add the two files to your local repository are:
  mvn install:install-file -Dfile=jms-2.0.jar -DgroupId=com.tibco.ems -DartifactId=jms -Dversion=2.0 -Dpackaging=jar -DgeneratePom=true
  mvn install:install-file -Dfile=tibjms.jar -DgroupId=com.tibco.ems -DartifactId=tibjms -Dversion=8.2 -Dpackaging=jar -DgeneratePom=true


The mvn command needs to be on your system PATH and the environment variable JAVA_HOME needs to be set to the install location of a reasonably recent JRE. The session below includes the errors which occur when these are not set.
  
Here is a typical session accomplishing adding these libraries to a private repository:
C:\tibco\ems\8.2\lib>dir *.jar
 Volume in drive C is Windows
 Volume Serial Number is E8A5-1438

 Directory of C:\tibco\ems\8.2\lib

09/28/2015  01:15 PM            40,067 jms-2.0.jar
09/28/2015  01:15 PM            15,279 slf4j-api-1.4.2.jar
09/28/2015  01:15 PM             7,470 slf4j-simple-1.4.2.jar
09/28/2015  01:15 PM           385,443 tibcrypt.jar
09/28/2015  01:10 PM             7,537 tibemsd_sec.jar
09/28/2015  01:15 PM           392,225 tibjms.jar
09/28/2015  01:15 PM           154,552 tibjmsadmin.jar
09/28/2015  01:15 PM            15,668 tibjmsapps.jar
09/28/2015  01:15 PM            67,955 tibjmsufo.jar
09/28/2015  01:15 PM            13,676 tibrvjms.jar
              10 File(s)      1,099,872 bytes
               0 Dir(s)  202,654,863,360 bytes free

C:\tibco\ems\8.2\lib>mvn install:install-file -Dfile=jms-2.0.jar -DgroupId=com.tibco.ems -DartifactId=jms -Dversion=2.0 -Dpackaging=jar -DgeneratePom=true
'mvn' is not recognized as an internal or external command,
operable program or batch file.

C:\tibco\ems\8.2\lib>set PATH=%PATH%;C:\Users\me\Downloads\apache-maven-3.3.9\bin

C:\tibco\ems\8.2\lib>mvn install:install-file -Dfile=jms-2.0.jar -DgroupId=com.tibco.ems -DartifactId=jms -Dversion=2.0 -Dpackaging=jar -DgeneratePom=true
Error: JAVA_HOME not found in your environment.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

C:\tibco\ems\8.2\lib>set JAVA_HOME=C:\tibco\sb-cep\10.1\jdk

C:\tibco\ems\8.2\lib>mvn install:install-file -Dfile=jms-2.0.jar -DgroupId=com.tibco.ems -DartifactId=jms -Dversion=2.0 -Dpackaging=jar -DgeneratePom=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing C:\tibco\ems\8.2\lib\jms-2.0.jar to C:\Users\me\.m2\repository\com\tibco\ems\jms\2.0\jms2-2.0.jar
[INFO] Installing C:\Users\me\AppData\Local\Temp\mvninstall8387646642699441771.pom to C:\Users\me\.m2\repository\com\tibco\ems\jms\2.0\jms2-2.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.579 s
[INFO] Finished at: 2017-04-27T15:12:20-04:00
[INFO] Final Memory: 15M/483M
[INFO] ------------------------------------------------------------------------

C:\tibco\ems\8.2\lib>mvn install:install-file -Dfile=tibjms.jar -DgroupId=com.tibco.ems -DartifactId=tibjms -Dversion=8.2 -Dpackaging=jar -DgeneratePom=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing C:\tibco\ems\8.2\lib\tibjms.jar to C:\Users\me\.m2\repository\com\tibco\ems\tibjms\8.2\ems-8.2.jar
[INFO] Installing C:\Users\me\AppData\Local\Temp\mvninstall2784652958246158057.pom to C:\Users\me\.m2\repository\com\tibco\ems\tibjms\8.2\ems-8.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.421 s
[INFO] Finished at: 2017-04-27T15:13:03-04:00
[INFO] Final Memory: 15M/483M
[INFO] ------------------------------------------------------------------------

After these libraries are added, you should then update your repository index in Studio and then add these as dependencies to your project.