One Star

[resolved] Component Compile Error using external libraries

I've created a new component, set all the paramaters etc.
In the code I want to refer to some libraries.
I've included these as part of the component creation and the statements are in the code generation stuff.
But if I add anything to the jet imports and try to push the component it just says there are compiles errors in the begin jet.
As the additional import is the only thing added I'm not sure what I've done wrong.
<%@ jet
imports="
org.talend.core.model.process.INode
.....
org.talend.core.model.metadata.types.JavaTypesManager
org.talend.core.model.metadata.types.JavaType
java.util.List
java.util.Map
com.hp.hpl.jena.rdf.model.*
"
%>
I've also tried referring to specifics as well com.hp.hpl.jena.rdf.model.Model
but it still gives this error.
.
The jar has been added in the lib java folder
I can use the import in routines without issue.... I just can't get my component to compile if I use an import.
Please help
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] Component Compile Error using external libraries

Ah belay that. I think I've seen my error.... I don't need to import it i the jet imports
5 REPLIES
One Star

Re: [resolved] Component Compile Error using external libraries

Ah belay that. I think I've seen my error.... I don't need to import it i the jet imports
One Star

Re: [resolved] Component Compile Error using external libraries

No still getting errors.
Saying that things can't be resolved. It looks like it can't see the llibraires.
Anyone help?
Phil
Seventeen Stars

Re: [resolved] Component Compile Error using external libraries

It depends what you want to do with your lib. If you want use java code running at the design time of of the job (like wizards) it is necessary to add them as plugin to Talend.
If the lib contains java code which should be used in the runtime of the job, it is quite enough to add your library in the XML in the codegeneration tag as import (use the code completion to have a body for it).
One Star

Re: [resolved] Component Compile Error using external libraries

Hi jlolling
I have declared the library in the xml as part of using the component creation wizard.
it created the following entry in the xml and copied the .jar to the lib/java folder.
<CODEGENERATION>
<IMPORTS>
<IMPORT MODULE="jena-core-2.10.1.jar" NAME="jena-core-2.10.1" REQUIRED="true"/>
</IMPORTS>
</CODEGENERATION>
In my begin code I want to instantiate an object from the library.
such as
// create an empty model
Model model_<%=cid %> = ModelFactory.createDefaultModel();
.....
I can push the component to the palette with out error.
I can bring the component into a job
but when I run the job i get an error
saying "Model cannot be resolved to a type"
The code I am using in the begin works fine in a routine. but there I am explicitly adding an import to the class.
I just cannot get it to work in a component.
Any thoughts?
Cheers
Phil
One Star

Re: [resolved] Component Compile Error using external libraries

I see one of my errors
I needed to be more explicit e.g.
com.hp.hpl.jena.rdf.model.Model model_<%=cid %> = com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel();
Now it can resolve all the types correctly but now when trying to run the component i get

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
I have added slf4j-api-1.6.4.jar to the xml code gen imports tags
copied the jar to lib java.
but I still can't get past this one.
I'm not calling directly myself so it must be Talend or the classes I am creating.
There seems to be a bit about this on talend jira but I can't see what is causing it.
Help Please !
Cheers
Phil