One Star

How to create Routines and Use them in tJava

Hi
I have a particular business requirement for which I had to write my own java code and Now I want to put this code into routines.
The problem I encounter is strange Even though I tell it to put in a particular package It doesn't put the code into that package and even if I change it manually it keeps giving me errors.
It always put my code into some weekly_dashboard package.
And Pls give me information on how to use these routines in tJava or any component once I get this working.
Thanks
Surya
16 REPLIES
Community Manager

Re: How to create Routines and Use them in tJava

Hello
weekly_dashboard is your project name, all the routines created by users are put in the package: routines.projectName.
The problem I encounter is strange Even though I tell it to put in a particular package

You are creating some folders, not package.
Please see the screenshots.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to create Routines and Use them in tJava

Hi Shong
Thanks for the quick reply.
But I am still facing the same problem sending you screen shots of all the steps.
I followed your instructions but still it gives errors in the package.
Thanks
Surya

Re: How to create Routines and Use them in tJava

hi,
i created a dummy routine under a folder called:
forumQuestions
NOTE: the name of the folder does not need to be used.
my routine:
package routines.proj_comcare;
public class ShowMyMessage {
/**
* ShowMyMessage: not return value, only print "hello" + message.
*
*
* {talendTypes} String
*
* {Category} SomeCategoryToChoose
*
* {param} string("world") input: The string need to be printed.
*
* {example} helloExemple("world") # hello world !.
*/
public static void helloExample(String message) {
if (message == null) {
message = "World";
}
System.out.println("Hello " + message + " !");
}
}

NOTE: there is the Category - that is what is used by the tJava components
{Category} SomeCategoryToChoose
EXAMPLE:
create a new job add a tJava and press CTRL + space; i get the screenshot below:

then in tJava i end up with:
ShowMyMessage.helloExample("nicolas message 1");

hope it helps,

Nicolas

www.brainpowered.net
One Star

Re: How to create Routines and Use them in tJava

Hi Nicholas
Thanks for the response but the problem I am facing is that when ever I create a routine the routine starts throwing errors as shown in image no matter what I put in package name it keeps giving me the same error.
I am little stuck here :-(
Regards
Surya
One Star

Re: How to create Routines and Use them in tJava

HI
Any body from Talend Support Pls help :-(
I am right now stuck at this point.
Regards
Surya

Re: How to create Routines and Use them in tJava

suryavikas,
could you please post the code of your routine or use the code that i have posted?
i am using version 3, what version are you using?
Nicolas
One Star

Re: How to create Routines and Use them in tJava

Hi Nicolas
Pls find step by step details how I create routine but it doesnt work for me :-( and I am also using Talend 3
Code of the routine.
// template routine Java
package routines.weekly_dashboard;
/*
* user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but
* it must be before the "{talendTypes}" key.
*
* 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character,
* long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short |
* Short
*
* 3. {Category} define a category for the Function. it is required. its value is user-defined .
*
* 4. {param} 's format is: {param} <type> <name>
*
* <type> 's value should be one of: string, int, list, double, object, boolean, long, char, date. <name>'s value is the
* Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't
* added. you can have many parameters for the Function.
*
* 5. {example} gives a example for the Function. it is optional.
*/
public class test123 {
/**
* helloExample: not return value, only print "hello" + message.
*
*
* {talendTypes} String
*
* {Category} User Defined
*
* {param} string("world") input: The string need to be printed.
*
* {example} helloExemple("world") # hello world !.
*/
public static void helloExample(String message) {
if (message == null) {
message = "World";
}
System.out.println("Hello " + message + " !");
}
}
Attached images of the step by step process.
Regards
Surya
One Star

Re: How to create Routines and Use them in tJava

Any inputs
Pls help :-(

Surya
One Star

Re: How to create Routines and Use them in tJava

what is the error that you're getting at this line?
package routines.weekly_dashboard;

i think you need to change it back to
package routines;
One Star

Re: How to create Routines and Use them in tJava

Hi
Pls find the error message I get.

The declared package "routines.weekly_dashboard" does not match the expected package ""

Regards
Surya
One Star

Re: How to create Routines and Use them in tJava

Yea, I think you need to change it, like I said in my last post.
One Star

Re: How to create Routines and Use them in tJava

Hi
I have tried that, still my program gives me the same error.
Surya
One Star

Re: How to create Routines and Use them in tJava

Did you save it? Also, it shouldn't be giving you the exact same error, since your declared package name has changed.
One Star

Re: How to create Routines and Use them in tJava

Hi
Yes I did save it and even after changing the package to routines it gives the same error.

The declared package "routines" does not match the expected package ""
Attached Image to show.
Thanks
Surya

Re: How to create Routines and Use them in tJava

hi,
by default the package definition is:
package routines.<project name>;
in you case;
package routines.weekly_dashboard;
unfortunately, i got no suggestions. but for argument sake try creating another project and a routine in it.
Community Manager

Re: How to create Routines and Use them in tJava

Hello
The package name is fixed and it always is routines. I remember there was a bug about can't save the routine after edit it on previous version and it have been fixed on the latest version.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business