Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Gadje
Contributor III
Contributor III

Using external custom .jar in job Talend (Parsing PDF)

I made a custom .jar executable that parsing some PDF files and catching some text values, depending a regex.

All works fine.

Now, i would like to use it in Talend job but i don't know how to do it.

I tried with tLibraryLoad component but it didn't work.

I tried to :

  1. Create a routine in the code section. Save it.
  2. Right click on the routine to edit the routine libraries. Locate and add your jar.
  3. Edit the dependecies of your job and add the created routine.
  4. Add the required import in a tJava component.
  5. You should be able to use the library in the tJava from now

But didn't work too.

 

Is ther somebody who knows how i can do that.

Thanks from advance.

Labels (2)
10 Replies
Anonymous
Not applicable

Hello,

Could you please let us know if this article helps?

https://community.talend.com/s/article/Best-practices-for-adding-custom-libraries-in-Talend-Jobs-rou...

Best regards

Sabrina

Gadje
Contributor III
Contributor III
Author

Hello xdshi,

Thanks for your reply.

I use Talend 6.3.1. i didn't see anything concerning TAC.

If i try to import iText directly in Talend package explorer, i have an "BUILD FAILURE" message.

I don't understand anything in the page link yau gave me. Sorry.

Gadje
Contributor III
Contributor III
Author

I'm unable to connect to Maven repository.

 

[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Cannot access central (http://repo.maven.apache.org/maven2) in offline mode and the artifact org.apache.maven.plugins:maven-resources-plugin:jar:2.6 has not been downloaded from it before. -> [Help 1]

 

Offline / Missing artifact com.itextpdf:itextpdf:jar:5.5.13.2

Anonymous
Not applicable

Hello,

Using a tLibraryLoad component to load the jar at the beginning of job, and then write the custom code on tJava, eg:

tLibraryLoad

|

onsubjobok

|

tJava

What's error are you getting?

Best regards

Sabrina

Anonymous
Not applicable

Hello,

You could delete the configuration/.m2 and re-download the jar files which the one that is the issue in this scenario is your routines jar file.

Best regards

Sabrina

Gadje
Contributor III
Contributor III
Author

Hello Xdshi,

 

I used a tLibraryLoad component as show in 1 below and i loaded my executable jar ParserPdf.jar as show in 2, 3, 4.

0693p00000AHjkUAAT.jpg 

I connected the tLibraryLoad component to tJava componenent with OnSubjobOk link.

I just called my class as show in 2.

0693p00000AHjkZAAT.jpg 

This is the issue message i obtain in 2

0693p00000AHjkeAAD.jpg 

I deleted the /.m2 repository but i dont know what to do after.

Thanks from advance.

Gadje
Contributor III
Contributor III
Author

I tried another way with tSystem component as show below.

0693p00000AHlQWAA1.jpgBut i didn't catch nothing in my consol output.

0693p00000AHlQqAAL.jpgI continue my quest. 😅

 

Anonymous
Not applicable

Hello,

To enable this tLibraryLoad component to load an external library, you need first to import the library into the component.

Best regards

Sabrina

Gadje
Contributor III
Contributor III
Author

Hi,

I found how to do for displaying returned values from my .jar with tSystem component. But now i would like to know how catch this values in a tMap component.

 

If i use this configuration (console output) :

0693p00000AYgM4AAL.jpg 

I can displaying the values returned by jar :

0693p00000AYgM9AAL.jpg 

But if i configure the tSystem output to global variable as below :

0693p00000AYgMEAA1.jpg 

i don't have anything in output :

0693p00000AYgMJAA1.jpg 

Maybe my problem come from my jar code. i puting it here :

 

import com.itextpdf.text.pdf.PdfReader;

import com.itextpdf.text.pdf.parser.PdfTextExtractor;

//import java.io.*;

import java.util.regex.*;

 

import java.io.IOException;

 

public class ParserPdf{

   public static Pattern pattern;

   public static Matcher matcher;

   public static String cdeadh="";

   public static String numcmd="";

   public static String result="";

   public static String newName="";

 

 

   public static void main(String[] args) {

      for(int i=0; i<args.length; i++) {

         newName=reader(args[i]);

         System.out.println(newName);

         reader(args[i]);

      }

  }

 

 

   public static String reader(String file) {

       PdfReader reader;

       String res="";

 

       try {

           reader = new PdfReader(file);

 

           String textPdf = PdfTextExtractor.getTextFromPage(reader, 1);

           //System.out.println(textPdf);

           reader.close();           

           res=finderCopab(textPdf, "AD"+"[0-9]{3}"+".*");

           res=finderArca(textPdf, "22"+"[0-9]{3}"+"[A-Z]"+".*");

           res=finderCesaea(textPdf, "CESAEA"+".*");

           res=finderCesaew(textPdf, "CESAEW"+".*");   

 

       } catch (IOException e) {

           e.printStackTrace();

       }

       return res;

   }   

 

   // Finder ADH COPAB

   public static String finderCopab(String data, String regEx) throws IOException {   

      pattern = Pattern.compile(regEx);

      matcher = pattern.matcher(data);

      while(matcher.find()) {

         //cdeadh=matcher.toString();

         //System.out.println(cdeadh);

 

         cdeadh=matcher.toString().substring(69, 74);

         numcmd=matcher.toString().substring(98, 104);

 

         result=cdeadh+"_"+numcmd;

         //System.out.println(result); 

      }

      return result;      

   }

 

   // Finder ADH ARCA

   public static String finderArca(String data, String regEx) throws IOException {   

      pattern = Pattern.compile(regEx);

      matcher = pattern.matcher(data);

      while(matcher.find()) {

         //cdeadh=matcher.toString();

         //System.out.println(cdeadh);

 

         cdeadh=matcher.toString().substring(74, 80);

         numcmd=matcher.toString().substring(103, 109);

 

         result=cdeadh+"_"+numcmd;

         //System.out.println(result); 

      }

      return result;      

   }

 

   // Finder cession CESAEA

   public static String finderCesaea(String data, String regEx) throws IOException {   

      pattern = Pattern.compile(regEx);

      matcher = pattern.matcher(data);

      while(matcher.find()) {

         cdeadh=matcher.toString().substring(65, 72);

         //System.out.println(cdeadh);

         if(!cdeadh.equals("CESAEA/")) {

            cdeadh=matcher.toString().substring(65, 71);

            numcmd=matcher.toString().substring(94, 100);

 

            result=cdeadh+"_"+numcmd;

            //System.out.println(result); 

         }

      }

      return result;      

   }

 

   // Finder cession CESAEW

   public static String finderCesaew(String data, String regEx) throws IOException {   

      pattern = Pattern.compile(regEx);

      matcher = pattern.matcher(data);

      while(matcher.find()) {

         cdeadh=matcher.toString().substring(65, 72);

         //System.out.println(cdeadh);

         if(!cdeadh.equals("CESAEW/")) {

            cdeadh=matcher.toString().substring(65, 71);

            numcmd=matcher.toString().substring(94, 100);

 

            result=cdeadh+"_"+numcmd;

            //System.out.println(result);

         }

      }

      return result;      

   }

}