As background for this read the article “Exporting a Job script and executing it outside of Talend Studio” at this link

Prerequisite

First create and test the Talend job from within Talend Open Studio. Use context variables to support different contexts.

When satisfied then export the job script

  1. Right-click the Job you want to build in the Repository view.
  2. Select Build Job to open the [Build Job] dialog box.
  3. In the To archive file field, browse to the directory where you want to save your built Job.
    1. A good practice is to place Talend jobs in <client_sch_dir>\custom\talend
  4. From the build type list, select the Standalone Job.
  5. Select the Extract the zip file check box if you want the archive file to be automatically extracted in the target directory.
  6. Click Finish to validate your changes, complete the build operation and close the dialog box.
  7. A zipped file for the Jobs is created in the defined place.

If the Talend job has the name “MyJob”, then you will at this point be able to run the Talend job from e.g. Windows Explorer by double clicking <client_sch_dir>\custom\talend\MyJob\MyJob_run.bat

If you make changes in Talend Open Studio to the job, repeat all of the above steps again to re-publish the changes.

Directly Running Talend Job without calling a bat file

This the recommeded approach. With this approach we start the Talend job in an external Java process, but using the embedded Java runtime installed as part of the ROB-EX client.

Follow these steps:

  1. To avoid having to specify too many parameters, then from within Talend Open studio select “Window->Preferences->Talend->Import->Export->“Add classpath jar in exported jobs” like shown below
  2. Rebuild your Job like described in the prerequisites at the top of this page.
  3. Create a ROB-EX Macro (Functions->Macro->Edit->New)
  4. Add the “RunExternalProgram” macro command. Edit the macro command to read e.g.

    Notice the program parameter bin\jre\bin\java.exe. The parameters are the command line setting used in the bat file “MyJob_run.bat” as explained above in the Prerequisite section. Make sure the path to the classpath.jar file is adjusted to be relative from the ROB-EX client install location, avoiding to hard code the full path (e.g. custom\talend\job\MasterMaterialAndInventory\classpath.jar). A full parameter line make look like this: -Xms256M -Xmx1500M -cp "custom\talend\job\MasterMaterialAndInventory\classpath.jar" robextalend.mastermaterialandinventory_0_1.MasterMaterialAndInventory --context=Default

This is an example bat file, copy the parameters marked in with dark highligh color. Be careful to modify the path to the classpath.jar file before applying in the macro.

%~d0
cd %~dp0
java -Xms256M -Xmx1024M -cp classpath.jar; robextalend.mastermaterialandinventory_0_1.MasterMaterialAndInventory  --context=Default %*

Running Talend Job using a bat file

This is an alternative approach to running it directly with Java. It is not the recommended approach, since the java.exe needs to be in the computer search path. Also a .bat file cannot suport UNC paths. We have in addition experienced customers not being allowed to run external bat files. The direct approach described above is the recommended approach, as it uses the embedded java shipped with ROB-EX.

Follow these steps to use a .bat script:

  1. Create a ROB-EX Macro (Functions->Macro->Edit->New)
  2. Add the “RunExternalProgram” macro command. Edit the macro command to read e.g.

    Notice how the value in “program” is relative from the ROB-EX startup directory – this way avoiding to hard code the full path.
  3. The output from a TalendJob will typically be a ROB-EX XML file, so a normal next step of your ROB-EX macro is to call the “XMLImport” macro command.
  4. Important note: the standard cmd.exe does not support UNC paths. If you need to run the Talend Job from a UNC path, then either
    1. Follow the instructions on how to “Directly Running Talend Job without calling a bat file” given above
    2. Or alternatively edit the .bat file to look like this (add the highlighted text). The reason this will work is that the pushd will automatically create a temporary drive letter pointing to the network path of the UNC path.
rem %~d0
rem cd %~dp0
pushd %~dp0
java -Xms256M -Xmx1024M -cp classpath.jar; robextalend.mastermaterialandinventory_0_1.MasterMaterialAndInventory  --context=Default %* 
popd

Feedback

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.

Post your comment on this topic.

Post Comment