Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

creation component - import java libraries

Hi,
I create a new java component, which use java libraries. So i add at beginning of my script
<%@ jet
imports="
org.talend.core.model.process.INode
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.core.model.process.ElementParameterParser
java.awt.Image
javax.imageio.ImageIO
"
%>
But then i trie to use this component in mjob , the generator doesn't add lines in script. Why ?
Labels (3)
18 Replies
Anonymous
Not applicable
Author

G'day,
I have the same problem (I think): I created a component of my own that uses different external libraries and when I try to execute my job with this component, I have a "My_Class cannot be resolved to a type".
The only workaround I know is to use tLibraryLoad to load my libraries one after the other but, when I have many different libraries, it soon becomes quite chaotic in the "Job Design View" screen as there must be one component by library.
My question is: Is it possible to load the content of a folder in the CLASSPATH instead of having to select one JAR at a time?
I have tried to put my jar in the same folder as my component (like I saw for some other components such as 'tJasperOutput' for example) but it doesn't seem to be working. What am I missing there?
Thanks again for your help and keep on the good work guys!
Chris
Anonymous
Not applicable
Author

you have to modify the xml file corresponding to your component.
for my chart components I use jfreechart and jcommons so I've put this line to my xml :
<CODEGENERATION>
<IMPORTS>
<IMPORT NAME="JFreeChart" MODULE="jfreechart-1.0.3.jar" REQUIRED="true"/>
<IMPORT NAME="JCommon" MODULE="jcommon-1.0.6.jar" REQUIRED="true"/>
</IMPORTS>
</CODEGENERATION>
I hope it will help you
olivier
Anonymous
Not applicable
Author

Super cool !!!
Cheerios !
Chris
Anonymous
Not applicable
Author

you'll welcome 0683p000009MA9p.png
Anonymous
Not applicable
Author

hi,
doing my first Component , i've got similar problem !
I've added element IMPORT in configuration XML file :
<CODEGENERATION>
<IMPORTS>
<IMPORT NAME="jcifs" MODULE="jcifs-1.3.0.jar" REQUIRED="true"/>
</IMPORTS>
</CODEGENERATION>

and also modified string imports of begin javajet :
<%@ jet
imports="
org.talend.core.model.process.INode
org.talend.core.model.process.ElementParameterParser
org.talend.core.model.metadata.IMetadataTable
org.talend.core.model.metadata.IMetadataColumn
org.talend.core.model.process.IConnection
org.talend.core.model.process.IConnectionCategory
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.core.model.metadata.types.JavaTypesManager
org.talend.core.model.metadata.types.JavaType
java.util.List
java.util.Map
jcifs.smb.NtlmPasswordAuthentication
jcifs.smb.SmbException
jcifs.smb.SmbFile
jcifs.smb.SmbFileInputStream
jcifs.smb.SmbFileOutputStream
"
%>

without "jcifs import" it works (no compilation problem) ... but when I add these ones , I've a "Component compile fail".
I've tried to add jcifs jar file in Talend lib repository, and also in my componenent repository ...!
thanks for your help
laurent
Anonymous
Not applicable
Author

Hello kzone,
The import in the scriptlet part (<% %>) are only used when generating the component templates.
You can't do import for code executed at runtime of your job.
In your component javajet remove the import declaration and then use the fully qualified class names
for example :
jcifs.smb.SmbFileInputStream sis = new jcifs.smb.SmbFileInputStream(...);

HTH,
Anonymous
Not applicable
Author

hi mhirt,
thanks for your explanation and precisions ....
hope now i 'll be able to finish it , and put it in the ecosystem !
++
Anonymous
Not applicable
Author

You can't do import for code executed at runtime of your job.

Is this going to be changed in future versions? or is this a design desision?
Regards,
Bas van Reeuwijk.
Anonymous
Not applicable
Author

It's a design choice : if component A and component B use 2 Array class in 2 different packages, they can not be used in the same Job if we add an import feature.
Fully qualified name is the only solution to avoid such problems.
Best Regards,