Using tLibraryLoad to import custom code

One Star

Using tLibraryLoad to import custom code

I am testing out Talend's custom Java capabilities.  For reference, I am running Talend 6.1.0.20151029_1337. 
I wanted to see if I could load in a custom class and run it as part of a Job.  After reviewing the documentation on tLibraryLoad and checking a few examples, I added a tLibraryLoad component and clicked the (...), specifying my custom jar file as my library.  Then, in advanced settings, I imported the desired class and hooked up a tJava component via "onSubjobOk" to run it.
However, when I try to compile and run the job, I get "The import XXX cannot be resolved"
I left the .jar in my eclipse project directory.  I assumed that, since I was able to find it with the file browser when setting up my tLibraryLoad component, Talend would be able to retrieve and use the jar.  Is there something I'm doing wrong?
One Star

Re: Using tLibraryLoad to import custom code

Yes, Talend was able to retrieve and use the .jar, but I think your import statement is the problem, hence the  "The import XXX cannot be resolved" error. Why dont you just remove the import statement altogether so the whole .jar would be imported, you can then use the specific class or function later in your Talend job.
One Star

Re: Using tLibraryLoad to import custom code

I removed the import and tried to call a static method from one of the jar's classes, once more.  Now, I get the "<classname> cannot be resolved" error on the tJava component.
Is the import not necessary to pull in a particular class in Talend?  Why would I need to remove it? 
Moderator

Re: Using tLibraryLoad to import custom code

Hi,
Could you please post your job screenshots into forum so that we can see if there is anything wrong with your setting?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Using tLibraryLoad to import custom code

As requested, here is a screenshot of the job layout, the Basic & Advanced Settings of my tLibraryLoad component, and the code in my tJava component.  Assume FlowConverter is a class within the jar that I am referencing.

One Star

Re: Using tLibraryLoad to import custom code

I came back from holiday and noticed that I didn't get a response to this.  Running custom Java code in line with other Talend components is one of the requirements we had in mind for using Talend in our ETL process.
Is there any known solution for this? 
Moderator

Re: Using tLibraryLoad to import custom code

Hi,
Sorry for delay!
Have you already checked the scenario in component reference TalendHelpCenter:tLibraryLoad?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Using tLibraryLoad to import custom code

Yes, that was actually my reference when I first set up this test case.  Also, as an update, to be sure that my jar file hasn't been causing the problem, instead of using my own jar, I am now attempting to use the Apache Commons Lang library as my test library.
To reiterate, I:
- created a tLibraryLoad component and browsed my files to find the commons-lang3-3.4.jar file
- specified under the tLibraryLoad's Advanced Settings the following import: "import org.apache.commons.lang3.StringUtils;"
- connected to a tJava component via an onSubjobOk trigger
- configured the tJava component to execute the code: "System.out.println(org.apache.commons.lang3.StringUtils.capitalize("word"));"
This resulted in the same error as before, instead referring to the new import: "The import org.apache.commons cannot be resolved"
The example is fairly simple and this library is very widely used.  I can't seem to figure out what's going wrong.  Any ideas?
One Star

Re: Using tLibraryLoad to import custom code

I'm having a similar issue in 6.1.1. When I browse to a library and include it in a tLibraryload it is not showing up in the modules tab. Other users in the same project should see it in the drop down. I think libraries lost some functionality in 6.0.1 and 6.1.1
One Star

Re: Using tLibraryLoad to import custom code

If this is indeed a bug, I hope it gets resolved soon.  Where is the appropriate place to report a bug?  Being able to run custom code in a workflow is a requirement for a few of our future ETL use cases.