Six Stars

Import Jar in Component

Hello,

 

I am writing a component for TOS 6.4.1 in which I want to use ARX Anonymasiation (http://arx.deidentifier.org/). I downloaded the jar from the homepage and importet it to my component (see the XML) and added it to the Java Build Path in TOS.

 <IMPORTS> 
      <IMPORT MODULE="libarx-3.6.0.jar" NAME="libarx" REQUIRED="true"/> 
    </IMPORTS> 

Now I want to use one of the classes.

In the _begin.javajet file I write

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
		org.deidentifier.arx.ARXAnonymizer
	" 
%>
<% 
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
INode node = (INode)codeGenArgument.getArgument();
String cid = node.getUniqueName();

 	
org.deidentifier.arx.ARXAnonymizer anonymizer = new org.deidentifier.arx.ARXAnonymizer.ARXAnonymizer();
%>

but I keep getting an error message "The import org.deidentifier cannot be resolved".

 

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Seven Stars

Re: Import Jar in Component

Any code inside <% %> is processed by javajet template engine. Javajet engine is like preprocessor that outputs, java code which is later again complied by studio before execution.
So in our case whats happening ?
*Although jar is loaded correctly, it cant be imported and used for javajet engine codes.

Try putting your line of code, which gave the error ,at the end of javajet file outside <%%>.

Have a look at simple javajet file that uses a third party json lib.
https://github.com/Chirgal/tComponents/blob/master/src/main/java/tXmlToJson/tXmlToJson_begin.javajet
20 REPLIES
Moderator

Re: Import Jar in Component

Hello,

Have you put your jar file in your custom component folder? Can you see it from modules view?

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.
Moderator

Re: Import Jar in Component

Hello,

Have you put your jar file in your custom component folder? Can you see it from modules view?

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.
Six Stars

Re: Import Jar in Component

Hallo,

Yes the Jar is in the component folder. When I open the component Designer I can see it.

When I loaded the component for the first time it told me I need to install a required jar and I installed it with the component view of my Job.

Thank you for your reply.
Moderator

Re: Import Jar in Component

Hi,


miriull wrote:
Hallo,

Yes the Jar is in the component folder. When I open the component Designer I can see it.

When I loaded the component for the first time it told me I need to install a required jar and I installed it with the component view of my Job.

Thank you for your reply.

You are still getting an error message "The import org.deidentifier cannot be resolved"?

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.
Six Stars

Re: Import Jar in Component

Hey,

 

sadly I do. 

Do you have any idea why I get this error message?

 

Thanks,

Miri

Six Stars

Re: Import Jar in Component

Hello,

 

in the meantime I added the URLPath to the XML.:

 <IMPORTS> 
      <IMPORT MODULE="libarx-3.6.0.jar" NAME="libarx" REQUIRED="true" UrlPath="D:\Program Files\TOS_DI-20170623_1246-V6.4.1\plugins\org.talend.libraries.custom_6.4.1.20170623_1246\lib\libarx-3.6.0.jar"/> 
    </IMPORTS> 

But that does not help, either Smiley Sad

 

Greetings,

Miri

Seven Stars

Re: Import Jar in Component

@ miriull referring to your _begin.javajet file, Shouldnt the line of code be
org.deidentifier.arx.ARXAnonymizer anonymizer = new org.deidentifier.arx.ARXAnonymizer();

Instead of

org.deidentifier.arx.ARXAnonymizer anonymizer = new org.deidentifier.arx.ARXAnonymizer.ARXAnonymizer();
??
Six Stars

Re: Import Jar in Component

Hey,

You are rigth, there is a mistake. Anyway it doesn't even find org.deidentifier so that doesn't seem to be the problem.

Greetings,
Miri
Seven Stars

Re: Import Jar in Component

Can you upload your component XML file please?
Six Stars

Re: Import Jar in Component

Sure.

 

Greetings,

Miri

Seven Stars

Re: Import Jar in Component

You can try changing custom component location.
Alternatively, you can use tLibraryLoad component to load libarx jar explictly in your talend job.
Six Stars

Re: Import Jar in Component

I already tried more than one location for the as as well as the whole component.

 

The import with the tLibraryLoad only works if I write my code in tJavaFlex. But the import of the jar for the component doesn't seem to work. Furthermore I cannot connect tLibraryLoad with my component.

I also think that this is not the best solution: I want to offer the functionality of arx within this component. When the user has to load the Jar in an external component he doesn't need the extra component any more..

 

Greetings,

Miri

Seven Stars

Re: Import Jar in Component

I agree, this is not the solution.
What i meant is,you can test the new component using tLibraryLoad. (I am sure jar would be available to new component).

The probable reason for your error is , not the latest XML for your component is being compiled by studio. In which case , you should try by changing your custom component location and workspace.
Six Stars

Re: Import Jar in Component

Even when I use tLibraryLoad I get the error message. My Job looks like that

Unbenannt.PNG

(File Input is a simple example csv for the analysis) 

 

I copied the component to a different direction and changed the component path of TOS to this folder but that doesn't help either.

 

Could there be a mistake in the import in the javajet?

 

Seven Stars

Re: Import Jar in Component

Remove org.deidentifier.arx from import section in javajet.
I guess import section is for library already packaged with jet engine.

Hope that helps !
Six Stars

Re: Import Jar in Component

It doesn't help.

The line 

org.deidentifier.arx.ARXAnonymizer anonymizer = new org.deidentifier.arx.ARXAnonymizer();

gives 2 errors: 2 times "org.deidentifier cannot be resolved to a type"

Seven Stars

Re: Import Jar in Component

Did you use tLibraryLoad this time?
Six Stars

Re: Import Jar in Component

It is the same job as the Screenshot you can see, so yes

Seven Stars

Re: Import Jar in Component

Any code inside <% %> is processed by javajet template engine. Javajet engine is like preprocessor that outputs, java code which is later again complied by studio before execution.
So in our case whats happening ?
*Although jar is loaded correctly, it cant be imported and used for javajet engine codes.

Try putting your line of code, which gave the error ,at the end of javajet file outside <%%>.

Have a look at simple javajet file that uses a third party json lib.
https://github.com/Chirgal/tComponents/blob/master/src/main/java/tXmlToJson/tXmlToJson_begin.javajet
Six Stars

Re: Import Jar in Component

Thank you so, so much! Smiley Very Happy

That really was the problem, I finally got it.

 

Greeting,

Miri