How to access a Java variable?

One Star

How to access a Java variable?

I've got a tJava and set a variable String var1 = "test";
Now I want to access this variable somewhere else, for example in a MsgBox or what else.
How can I access it?
There is only ERROR_MESSAGE .. _1_currentPath doesn't work either.
Can someone help me?
Thank you.
One Star

Re: How to access a Java variable?

You need to use the globalMap map variable or create a context variable and use that. The scope of the tJava components is limited. You need a global scoped variable.
Community Manager

Re: How to access a Java variable?

Frist, you need to set it to a global var. eg:
String var1="test";
then, use this var like this:
Best regards

Talend | Data Agility for Modern Business
One Star

Re: How to access a Java variable?

it works within one job, but when I call tRunJob and try to System.out.println the variable in the childjob I see: null
For the tRunJob I've choose to: Transmit whole content.
What do I have to do if I want to pass this variable to a child?
Bye, Chris
One Star

Re: How to access a Java variable?

The globalMap instance is specific to a job, transmitting the context to a child job wont changes this.
If you intent to transmit a variable to child job, use the context then, it should be straitforward.

Re: How to access a Java variable?

Existing two way to manage variable and parameter in a talend job.
1) globalMap is used to set variable in a Job, it's a hashmap
2) context var is used to set parameters
So, to achieve your goal,
1) you need to create context var in your childjob
2) With the tRunJob, use the context param tab, create a row, select the childjob context var in the first column, and set your expresion in the second one : globalMap.get("MyVar")
the transmit whole context checkbox is only for to transmit value of context var with same name from fatherjob to childjob.
One Star

Re: How to access a Java variable?

Eventually I got it .. I tried so hard to set a context in my fatherjob, I didn't get the idea to setup a context in the childjob! Smiley Sad
Thank you for your help! Smiley Happy
One Star

Re: How to access a Java variable?

How Can I share the global map between father an son job. I see that it's possible using context. In fact I have lots of parameters , so It will be hard to create a context variable for each parameter.
Thanks for your replay


Talend named a Leader.

Get your copy


Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables


How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration


Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.