Talend Studio provides a new approach to adding custom and third-party JAR files. When a Studio user adds a custom library into a Job, the library is uploaded to the Nexus shared library repositories. Syncing custom libraries to Nexus enables collaboration between all of the users on the project by enabling sharing and automatic downloading of the libraries to their local m2 repositories. It allows users to run Jobs easily and to add libraries into new Studio Jobs, routines, beans, and routes.
This article explains the best practices that Talend suggests you follow when adding custom / third-party libraries into Jobs, routines, routes, and beans.
Sources for the project are attached to this article.
Install Talend 7.0, 7.1, or 7.2.
Configure TAC and Nexus settings for shared libraries (follow the instructions in the Custom libraries process KB article).
Create a Project in TAC (this article uses, LibraryManagement).
Create two users in TAC (this article uses, userA@talend.com and userB@talend.com).
Authorize users to have Read/Write permissions in TAC.
The following diagram depicts how the upload, sync, and sharing happens:
Create a simple Maven project as a JAR module.
In Talend Studio, click the Open Perspective icon, then select Java
Create a Java Maven project called LibraryManagement.
Create a Maven module called Greet.
Create a Java file called Greet.java that returns a Welcome message.
Note: in this step, you create a custom JAR file to use in Talend Jobs / Routes.
Navigate to Configuration > User Libraries.
Verify that your Nexus repository details are configured correctly.
This section shows you (logged in as userA) how to create a Job, routine, bean, and a route, and add a custom library as a dependency.
Create a standard Data Integration (DI) Job called Job_LibraryManagement.
In the Designer, add a tLibraryLoad, component. Click the [...] button to the right of the Library field.
In the popup window, select the Artifact repository(local m2/nexus) radio button, then select the Install a new module radio button. Click the [...] button on the right, then add the new Greet-0.0.1-SNAPSHOT.jar module.
Note: There is a warning message, "Please detect if the module already installed with maven URI".
Click the Detect the module install status button.
Because the module Greet-0.0.1-SNAPSHOT.jar doesn't exist in the Nexus repository, you can upload this version, and the warning message disappears automatically.
Observe the Default MVN URI field, the new module Greet-0.0.1-SNAPSHOT.jar is uploaded to the 6.0.0-SNAPSHOT folder of the nexus repository talend-custom-libs-snapshot.
Similarly, if you want to upload the release version of the Greet-0.0.1.jar module to the talend-custom-libs-release repository, create a release version of the Greet-0.0.1.jar module, select the Custom MVN URI check box, then, in the Custom MVN URI field add the following:
Click OK to upload the JAR to your Nexus repository.
In the Designer, add a tPrejob component, then link it to the tLibraryLoad component using the OnComponentOk trigger.
Add a tJava component, initialize the Greet class, then, in the Code window add a system.out to display the Greet message by adding the following:
org.talend.demo.customlibrary.Greet job_greetings = new org.talend.demo.customlibrary.Greet(); System.out.println(job_greetings.greet());
Run the Job, then view the Job execution details.
The Job executes the code from the Greet-0.0.1-SNAPSHOT.jar library and logs the Welcome to Talend. You are running version 1 of this library message.
Create a routine called Routine_Greet.
Right-click Routine_Greet, then select Edit Routine Libraries.
In the Import External Library window, select New.
Another pop-up window appears, select Greet-0.0.1-SNAPSHOT.jar on the Platform drop-down list. Click OK.
Note: the Greet-0.0.1-SNAPSHOT.jar library already appears in the Platform drop-down list because it was added to the project in the Add a library in Standard DI Job section of this article.
The library is added to the Routine, notice that the Required check box is enabled by default. Click Finish.
Enable the Required check box, if the Greet library is not already added to the Job design using a tLibraryLoad component or with any other Talend components. You can verify the external libraries used by the Talend components from the Studio Module view.
If the check box is disabled, it means the Greet library is already added to the Job and is used only as a compile-time dependency in the Routine.
Modify the Routine_Greet definition, update the helloExample method, then instantiate the Greet class.
Routine_Greet is now set to handle external dependencies.
Create a Job called Routine_LibraryManagement, right-click the Job, then select Setup routine dependencies.
Add a User routine as a dependency to the Routine_LibraryManagement Job, by following the steps, numbered in sequence, below:
Open the Routine_LibraryManagement Job, and add a tFixedFlowInput and tLogRow component.
Double-click the tFixedFlowInput, component to open its Basic setting view, edit the schema and in the Value column, add the string column message, Routine_Greet.helloExample(). The Job is now configured to use a routine that uses a custom library.
Run the Job and view the Job execution details.
The routine executes the code in the Greet-0.0.1-SNAPSHOT.jar library and logs the Welcome to Talend. You are running version 1 of this library message.
This section shows you how to create a new version of the Greet-0.0.2-SNAPSHOT.jar file to add to ESB Jobs.
In the Studio, go to the Java perspective.
Open the LibraryManagement project. In the pom.xml file, increment the version of the custom library to 0.0.2-SNAPSHOT.
Run Maven install and generate the Greet-0.0.2-SNAPSHOT.jar file.
Create a new route called Route_LibraryManagment, then add a cConfig component.
Double-click the cConfig component to open its Component view. In the Dependencies table, click the [...] button to the right of "newLine".
In the Select Module window, select the External modules radio button.
Add the new version of the external Greet-0.0.2-SNAPSHOT.jar library, notice that by default, the version field is always set to 0.0.1-SNAPSHOT.
As a best practice, when uploading SNAPSHOT artifacts, change the version to 6.0.0-SNAPSHOT.
Note: when uploading a RELEASE artifact to the talend-custom-libs-release repository, set the Version field to 6.0.0.
Notice that the JAR is added to the cConfig component.
Verify that the Greet-0.0.2-SNAPSHOT.jar is uploaded to the Nexus repository.
Note: Observe that the Greet library uploaded to Nexus under the 6.0.0-SNAPSHOT folder using the tLibraryLoad and cConfig components, respectively.
Open the Route_LibraryManagment route, click the Dependencies tab, then select the Bundle ClassPath check box.
In the Route_LibraryManagment route, click the Designer tab, then add a cTimer and cProcessor component.
Open the cProcessor component, and add the following:
Greet greetObj = new Greet(); String message = greetObj.greet(); System.out.println(message);
Run the route and view the execution details.
The route executes the code in the Greet-0.0.2-SNAPSHOT.jar library and logs the Welcome to Talend. You are running version 2 of this library message.
Create a new route called Route_BeanLibraryManagment.
Create a new bean called Bean_LibraryManagement, right-click the bean, then click Edit Bean Libraries.
In the Import External Library window, click the New button.
A popup window opens, select the external Greet-0.0.2-SNAPSHOT.jar library from the Platform drop-down menu, then click OK.
The library is added to the bean, select the Required button to include the library in the route build. Click Finish.
Open the Route_BeanLibraryManagment route, then add the cBeanRegister, cTimer, cSetBody, and cLogRow components.
Double-click the cBeanRegister component to open its Basic settings view, set Id to "greetBean", then, in the Code window, add the following:
beans.Bean_LibraryManagement greeting_from_bean = new beans.Bean_LibraryManagement(); beanInstance = greeting_from_bean;
Double-click the cSetBody component to open its Basic settings view, select Simple in the Language pull-down list, then in the Expression field, add the following:
Connect the cTimer, cSetBody, and cLogRow components.
Run the route and view the execution details.
The route executes the code both in the bean and Greet-0.0.2-SNAPSHOT.jar library and logs the Welcome to Talend. You are running version 2 of this library message.
When you build a route, all of the beans are built and added to the route as a dependency. Because all the beans share the same POM file adding multiple versions of the same external library doesn't guarantee the desired results in both Studio and OSGi environments.
The following example demonstrates the impact of using several versions of the same library in beans.
In the Repository, duplicate the route Route_BeanLibraryManagment, then create two new routes Route_A, Route_B.
In the Repository, duplicate the bean Bean_LibraryManagement, then create two new beans Bean_A, Bean_B.
Right-click Bean_A, click Edit Bean dependencies, then modify the bean to use the Greet-0.0.1-SNAPSHOT.jar library. Click Finish.
Right-click Bean_B, click Edit Bean dependencies, then verify that the bean is using the Greet-0.0.2-SNAPSHOT.jar library. Click Finish.
Open Route_A, click the cBeanRegister component to open its Basic settings view, then replace the contents in the Code window with the following:
beans.Bean_A greeting_from_bean = new beans.Bean_A(); beanInstance = greeting_from_bean;
Open Route_B, click the cBeanRegister component to open its Basic settings view, then replace the contents in the Code window with the following:
beans.Bean_B greeting_from_bean = new beans.Bean_B(); beanInstance = greeting_from_bean;
Run Route_A and view the execution details, observe a message is logged from the class in the Greet-0.0.1-SNAPSHOT.jar library.
Run Route_B and view the execution details, observe again the same message is logged from the class in the Greet-0.0.1-SNAPSHOT.jar library.
This explains why using multiple versions of custom libraries is not supported with beans.
In this section, you need to log in to Talend Studio as userB and open the Jobs that were created by userA.
Open the Standard Job Job_LibraryManagement.
Notice there is an error on the tLibraryLoad component, click the component to open its Basic settings view.
Click the Install button to automatically download the library from Nexus repository.
Run the Job without any modifications.
This article covered the best practices for adding a custom library into Jobs, routines, routes, and beans, how the libraries are synced to the Talend Artifact Repository, and how the libraries are shared by other project users.