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
- Right-click the Job you want to build in the Repository view.
- Select Build Job to open the [Build Job] dialog box.
- In the To archive file field, browse to the directory where you want to save your built Job.
- A good practice is to place Talend jobs in
<client_sch_dir>\custom\talend
- A good practice is to place Talend jobs in
- From the build type list, select the Standalone Job.
- Select the Extract the zip file check box if you want the archive file to be automatically extracted in the target directory.
- Click Finish to validate your changes, complete the build operation and close the dialog box.
- 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:
- 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
- Rebuild your Job like described in the prerequisites at the top of this page.
- Create a ROB-EX Macro (Functions->Macro->Edit->New)
- Add the “RunExternalProgram” macro command. Edit the macro command to read e.g.
Notice theprogram
parameterbin\jre\bin\java.exe
. Theparameters
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 theclasspath.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:
- Create a ROB-EX Macro (Functions->Macro->Edit->New)
- 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. - 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.
- 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
- Follow the instructions on how to “Directly Running Talend Job without calling a bat file” given above
- 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
Post your comment on this topic.