Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: scheduling a batch job

  1. #11

    Default

    Quote Originally Posted by viper View Post
    Quote Originally Posted by dkaminsky View Post
    Here is a sample crontab entry (assuming classpath and beanRefContext are set up properly):

    Code:
    0 6 * * 1-5 java org.springframework.batch.execution.bootstrap.support.BatchCommandLineLauncher -Djob.configuration.path=jobs/myJob.xml -Djob.name=myJob
    At 6AM every weekday morning, launch "myJob" from file "myJob.xml"

    ???
    If you don't know what this is, don't worry.

    It is a sample entry ("crontab" entry) to configure the built-in *NIX scheduling utility known as "cron" -- this is perhaps the simplest scheduler available to non-Microsoft users so I felt it would be a good example. Again, don't worry if it doesn't apply to you.
    Last edited by dkaminsky; Jan 15th, 2008 at 01:48 PM. Reason: added original post

  2. #12

    Default Classpath...

    Quote Originally Posted by robert.kasanicky View Post
    Note you need to have classpath configured first and only then you can use the crontab one-liner...
    Could someone show and example how to setup the classpath that includes all the proper deployment artifacts to make a batch applicaiton run under crontab?

    thanks,
    james

  3. #13

    Default

    Quote Originally Posted by jdepaul View Post
    Could someone show and example how to setup the classpath that includes all the proper deployment artifacts to make a batch applicaiton run under crontab?

    thanks,
    james
    One way is to use maven to launch the job - just add the snippet below to your pom.xml and use "mvn exec:exec -Djob.name=myJob -Djob.configuration.path=path/to/myJob.xml" as command (or you can hardcode the parameters).

    Code:
    <plugin>
                      <groupId>org.codehaus.mojo</groupId>
                      <artifactId>exec-maven-plugin</artifactId>
                      <executions>
                          <execution>
                              <goals>
                                  <goal>exec</goal>
                              </goals>
                          </execution>
                      </executions>
                      <configuration>
                          <executable>java</executable>
                          <arguments>
                              <argument>-classpath</argument>
                              <!-- automatically creates the classpath using all project dependencies, 
                                  also adding the project build directory -->
                              <classpath />
                              <!-- job configuration file -->
                              <argument>-Djob.configuration.path=${job.configuration.path}</argument>
                              <!-- job name -->
                              <argument>-Djob.name=${job.name}</argument>
                              <argument>
                                  org.springframework.batch.execution.bootstrap.support.BatchCommandLineLauncher
                              </argument>
                          </arguments>
                      </configuration>
                  </plugin>
    Last edited by robert.kasanicky; Jan 17th, 2008 at 03:03 AM. Reason: removed redundant arguments from plugin config

  4. #14

    Default

    Could someone show and example how to setup the classpath that includes all the proper deployment artifacts to make a batch applicaiton run under crontab?
    Maybe the simplest way is to ask maven to create appropriate application jar file:

    Code:
     <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <!-- mainClass>fully.qualified.MainClass</mainClass -->
                                <addClasspath>true</addClasspath>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>

  5. #15
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    you could also use maven to copy all of the jars into a lib directory using the maven dependency plugin to copy them. For example:

    mvn dependency:copy-dependencies -DoutputDirectory=../Lib

    http://maven.apache.org/plugins/mave...cies-mojo.html

    From there you could add the lib directory to your classpath when executing:

    java -jar ...BatchCommandLineLauncher -cp ../Lib

  6. #16

    Default

    The QuartzBatchJob class is basicly a copy-paste of BatchCommandLineLauncher#start method - maybe it is worth to extract this logic from the "command line" class?[/QUOTE]



    could you please post the an example of QuartzBatchJob file. It doesn't come with spring batch examples and what you say about BatchCommandLineLauncher does not apply because it seems that that class was replaced by CommandLineJobRunner. Thanks.

  7. #17

    Default

    if it is useful for someone, my QuartzBatchJob (on m5) for the example given above is this one and it works fine:

    public class QuartzBatchJob extends QuartzJobBean implements StatefulJob {
    private JobLauncher launcher;
    protected static final Log logger = LogFactory.getLog(QuartzBatchJob.class);
    private JobParametersFactory jobParametersFactory = new DefaultJobParametersFactory();

    protected void executeInternal(JobExecutionContext ctx)
    throws JobExecutionException {

    try {
    ApplicationContext context = new ClassPathXmlApplicationContext(
    "org/springframework/batch/sample/PersonaJobFunctionalTests-context.xml");
    context.getAutowireCapableBeanFactory().autowireBe anProperties(
    this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    String[] parametros={"par1=1","par2=2"};

    Job job = (Job) context.getBean("personaImportJob");
    JobParameters jobParameters = jobParametersFactory
    .getJobParameters(StringUtils
    .splitArrayElementsIntoProperties(parametros, "="));

    launcher.run(job, jobParameters);
    } catch (Throwable e) {
    logger.error("Job Terminated in error:", e);
    }

    // place your Job code here
    /** ********************** */
    System.out.println("EJECUTANDO QUARTZ JOB");
    }

    public void setLauncher(JobLauncher launcher) {
    this.launcher = launcher;
    }

    }

  8. #18

    Default

    The quartz sample has been ressurected after M5 and there is now QuartzBatchLauncher and eclipse launch configuration provided in the samples.

  9. #19

    Default

    Where is on m5 samples the eclipse launch configuration you say? I only see the same QuartzBatchLauncher that existed on m4 and nothing else.

  10. #20
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    It has been added since M5, so it's in the latest trunk but not M5 itself. It should be included in RC1.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •