user2144555
user2144555

Reputation: 1313

How to run a Talend Job on JBoss from a Maven project?

How can I run Talend Jobs from my Eclipse Maven Project, after I export the job from Talend Open Studio for Data Integration 5.3.1(on Windows 7)? What dependencies are specific to a job, and what dependencies are global?

My Eclipse Project is running on JBoss 5.1.0.GA. It runs a Talend Job for each kind of files that receives, performing an ETL process for each one. I'm exporting each job from Talend by doing "Export Job - Autonomous Job", and I'm adding the JAR files as dependencies of the Maven project. But I don't think I can run the jobs over the server doing this.

Upvotes: 1

Views: 1882

Answers (1)

andriy
andriy

Reputation: 4164

Seems like you are doing everything well, all you need is to create correct pom.xml, that will include jars and context.properties to your project. I'm creating an artifact that includes necessary files. Here comes an example of my pom:

    <copy todir="${project.build.outputDirectory}">
       <fileset dir="${basedir}/My_Job_Main/" includes="*.jar"/>
    </copy>
    <jar destfile="${project.build.outputDirectory}/myJar.jar">
      <zipfileset dir="${basedir}/My_Job_Main/" 
         includes="**/my_job_main/**"
         excludes="**/src/**,**/items/**"/>
    </jar>
    <zip destfile="${basedir}/target/my.artifact.id-1.0-SNAPSHOT.jar">
       <zipgroupfileset dir="${project.build.outputDirectory}" includes="*.jar"/>
    </zip>

Than add this artifact as dependency to your ear file.

In class where you will run this job, you should simply import Job class and execute function with:

My_Job_Main job = new My_Job_Main();
job.runJobInTOS(params);//params -> is the String array of context variables

Solution 2:

But this solution is that I do not like. So what I suggest is to export jobs as you are exporting and load them dynamically without deploying with Maven. It will give you a flexibility to make changes in jobs without restarting server.

Here is an example of code that will load dynamically job jar files and execute them:

URL [] urls = new URL[length];

File jar = new File("path_to_jo_jar_file");
urls[0] = jar.toURI().toURL();

String params[] = new String[length];
params[0] = "--context=Default";
params[1] = "--context_param";
params[2] = "paramName=paramValue";

Class<?>[] params_type = new Class[]{String[].class};
URLClassLoader child = new URLClassLoader(urls , this.getClass().getClassLoader()); 
Class classToLoad = Class.forName( "my_job_main.My_Job_Main", true, child);
Method method = classToLoad.getDeclaredMethod ("runJobInTOS", params_type);
method.setAccessible(true);
Object instance = classToLoad.newInstance();
method.invoke(instance, new Object[]{ args } );

Hope this helps. If you have more questions, post in comments.

Upvotes: 1

Related Questions