Not applicable

can we import a java file

HI All,
I am using the Talend2.0.4(java), i need to use the functions number of times, for this i want to create a java object , import the object and make calls to the functions for reusability.
Can you help me anybody how to import a java file if it is possible.
Thanks,
Chandra
8 REPLIES

Re: can we import a java file

Hi Chandra,
You could try and use the tJava component (with fully qualified names for any of the Classes that you may use), the class that you wish to call should be in the class path other wise the code may not work.
Not applicable

Re: can we import a java file

Hi Mithungonsalvez,
I used the tJava component i tried to write the method and the calls, but the generated code(method and calls) is going to Main method, which i am getting the errors(ie.we should not write the method in main method).
Can you send me a example to import a java class and call the methods of it.
Thanks,
Chandra

Re: can we import a java file

Hi,
This is what i have understood from your question :
Call a method which is in another class multiple times.
So the following steps may be preformed (in the tJava component)
===========================================
1. Create the instance of the class.
2. Use the instance to call the method.
3. De-initialize the component, if it is not used anymore else store it in the globalMap.
As for the method call present in the main method, this is hard-coded in the Talend Code generation mechanism (i think... someone correct me if i am wrong) and the only way to change this is to change some parts of Talend Framework.
(or)
A work around is that u can have another class that has a main method that calls this one.
(or)
Create a custom component which does your task (here also the main method problem may arise).

B.T.W. Could you please attach the code that you had put in the tJava comonent as well as the screen-shot of the job (since it may help me or anyone else to understand your problem better and provide you with a possible solution)

Hope That Helps Smiley Happy
Mithun
Employee

Re: can we import a java file

Hello Chandra,
Simply create a routine in the code menu.
Regards,
Michaël
Not applicable

Re: can we import a java file

Hi All,
I created routine and i can able to call the methods by passing the static parameters it is working fine, but here i need to call the function for the columns of the input XLS columns.
Can you help me anybody how to call the method to the XLS columns.
Thanks,
Chandra
Employee

Re: can we import a java file

Two solutions :
you can add a line in main of tJavaFlex : myRoutine.myMethod(row1.columnName);
or you can do it in a mapper.
Michaël.
One Star

Re: can we import a java file

hi,
Is my experience usefull for you ?
I create a routine in the code section ( picture 1 )
the code is :
--------------------------------------------------------------------------------------
//template routine Java
package routines;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class maConversionDeStringEnDate{
public static Date conversionDateFromString(String mydate, String formatDeDate){
java.text.SimpleDateFormat sdf = new SimpleDateFormat(formatDeDate);
Date result = Calendar.getInstance().getTime();

try{
result = sdf.parse(mydate);
}
catch(java.text.ParseException pe){
System.out.println(pe.toString());
pe.printStackTrace();
}
return result;
}
}
--------------------------------------------------------------------------------------
in a tMap component i use it like that :
(row2.DateSaisie.trim().length()!=0)?maConversionDeStringEnDate.conversionDateFromString(row2.DateSaisie, "yyMMdd"):null
where row2.DateSaisie is the manipulated data.
Not applicable

Re: can we import a java file

Hi All,
I am reading one Xls file, I wrote one routine.
Added tJavaRow to apply the method on one Column(Col1).
String s = routines.ClassName.method(input_row.Col1);
output_row.Col1 = s;
But Other Columns are not getting populated in the Xls output file.
To solve this i added
output_row.Col2 = input_row.Col2;
output_row.Col3 = input_row.Col3;
....
output_row.ColN = input_row.ColN;
But i want a solution to this without repeating the other columns(Col2 .. ColN).
Is There any way to split the columns and implement the Methods and join them before destination???
Can you please give me the solution to this.
Thanks,
Chandra.