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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

run Talend ETL jobs from java application

i am working on a web application for log management , so i want to know how to run a Talend ETL job ( which will import a log file , treat it , extract relevent fields and load it into a DB) from my java web application . 

I want to explain more : i beuild an interface using angular which contains a "import" button , i want that whenever i click on that button ( which will call a method on my java application) the ETL job that i've created in Talend, runs automatically and the data is loaded into the data base . 

I 'll be really gratefull if you help me out

Labels (2)
9 Replies
Anonymous
Not applicable
Author

I use this technique in a couple of jobs.

 

1) First of all you need to build your Job.

2) Once you are happy with it, "build it" (right click "Build Job") and find the Job Jar in the zip file. You will need this for your Java application.

3) Write your Java application and import your Job library (you may need to play around with dependencies to get this 100% correct).

4) Now you simply need to run your Job. Here is some Java code I use to start a particular job that I use for analysing my Talend source files ....

 

//Create an ArrayList to hold parameter values (context params)
java.util.List<String> paraList = new java.util.ArrayList<String>();

//Add JobPath context param
paraList.add("--context_param JobPath="+"/Applications/Development/Talend/6.2.1/studio/workspace/LOCAL_PROJECT/process/Framework/ControllerJobs/ExecuteLoad_0.1.item");

//Add JobName context param
paraList.add("--context_param JobName="+"ExecuteLoad");

//Add UpdateTalendWorkspaceDataFile context param
paraList.add("--context_param UpdateTalendWorkspaceDataFile="+"true");

//Add WorkspaceProjectPath context param
paraList.add("--context_param WorkspaceProjectPath="+"/Applications/Development/Talend/6.2.1/studio/workspace/LOCAL_PROJECT");

//Add DataFile context param
paraList.add("--context_param DataFile="+"/Users/richardhall/Documents/test.xls");

//Create instance of Talend job
CalculateJobDependencies2 test = new CalculateJobDependencies2();

//Add params to Job and run it!
test.runJobInTOS((String[]) paraList.toArray(new String[paraList.size()]));

If you follow that, it should work for you after you have figured out library dependencies. Remember, this code is specific to my Job and my Job's context variables. Keep that in mind while you are extrapolating from this.

 

Good luck 🙂

Anonymous
Not applicable
Author

Hi, i read the post but  i have a question what is the difference between runJobInTOS(args) and runJob(args).  Becuase in my work we cannot install talend in the server machine. I have my station work where it´s installed talend in there  create the job , after build job after that create aplication after probe i send to the server. So in the example i see write the path so i´m confuse. 

I hope can help me.

 

Anonymous
Not applicable
Author

After you compile (build) your job you will get a zip file containing a bat/sh file for running your job and the relevant Jars. In my example above, I have a job called CalculateJobDependencies2. There is a Jar called that too (it has some version numbers after it, but it contains my Job classes). In my Java application I simply make use of the Jar and instantiate an object of the class like below....

 

 

//Create instance of Talend job
CalculateJobDependencies2 test = new CalculateJobDependencies2();

I then run the job via the runJobInTOS method which is part of all Talend Jobs. Below I am showing this (the paraList object refers to the parameters I was configuring for it in the code above). 

 

//Add params to Job and run it!
test.runJobInTOS((String[]) paraList.toArray(new String[paraList.size()]));

You do not need to install TOS on your server at all. You just need the Job and its packaged jars which are supplied when you build the job

Anonymous
Not applicable
Author

I should have added, runJobInTOS is the main method for running the job. runJob is simply a wrapper method for that method that returns a reformatted error code. You can see this if you search the code of your job

Anonymous
Not applicable
Author

hi, okay i doing this in my code.

 

public class Tzarcar_Cargar_Job {

	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		tzarcar.tzarcar_periodo_completo_0_1.Tzarcar_Periodo_completo pr = new tzarcar.tzarcar_periodo_completo_0_1.Tzarcar_Periodo_completo();
		
		String str_Per;
		String str_Porc;
		
		str_Per = "201015%";
		str_Porc = "0";
		String [] context=new String[] {"--context_param str_Per="+str_Per,"--context_param str_Porc="+str_Porc};
		//pr.runJob(context);
		
		System.out.println("Cargando Job");
		pr.runJobInTOS(context);
		System.out.println("Terminando Job");
		

	}

}

0683p000009M2Ta.png

Here is my images from eclipse when i charge the library.

 

But no work. 

 

Anonymous
Not applicable
Author

What error are you getting?

Anonymous
Not applicable
Author

0683p000009M30m.png

 

No error  nothing, when i run , it stay 10 minutes o more and finish run.

 

Anonymous
Not applicable
Author

Hi, it´s works .
Thx for help.
Anonymous
Not applicable
Author

No problem. Glad to help 🙂