Results 1 to 3 of 3

Thread: Does Command line batch require Spring container?

  1. #1

    Default Does Command line batch require Spring container?

    Hi all,

    I am trying to use Spring batch framework 2.1.3 to run batch from commandline (shell/bat) for linux/windows.
    What I am confused about it is that how and where to deploy it. What I have found after googling is that just putting jars and classes in a folder and running it from command line using 'java' will suffice.
    So my question is that how the dependency injection will work without web container in this case?
    Please help explaining it.

  2. #2
    Join Date
    Jul 2010
    Location
    USA
    Posts
    43

    Default

    Consider below as example.
    Put this in your shell script and define all variables properly. It should work


    Code:
    $JAVA_HOME/bin/java -Dlog4j.configuration=file:$......./log4j.xml -Xms256m -Xmx1024m -cp $CLASSPATH $JOB_RUNNER $CONFIG_FILE_PATH $JOB_NAME "jobParam1=$param1" "jobParam2=$param2"

    where
    JAVA_HOME=/usr/java/jdk1.6.0_03 #Jdk path
    CONFIG_FILE_PATH="file:/..........your-job-beans.xml"
    JOB_NAME="yourJob"
    JOB_RUNNER="org.springframework.batch.core.launch. support.CommandLineJobRunner"

    Dont forget to add your jars to the classpath

    For more information visit http://static.springsource.org/sprin...figureJob.html
    Last edited by anish555; Sep 29th, 2010 at 09:44 AM.

  3. #3
    Join Date
    Apr 2008
    Location
    Philadelphia, US
    Posts
    198

    Arrow

    Quote Originally Posted by kousik.majumder View Post
    So my question is that how the dependency injection will work without web container in this case?
    Please help explaining it.
    Can be confusing if you are coming from a comfy "web.xml" world where everything is bootstrapped for you

    But in reality there is no difference whether it is a web container ( e.g. Tomcat ) or a server with a command line interface: JVM can be agnostic of its whereabouts.

    So what really happens when you run "java <props> CommandLineJobRunner" including all the JARs, your JVM, that belongs to the process of the shell / or can be backgrounded ( via & ), is created and since your JARs will have Spring config files, the Spring ApplicationContext will be created within that JVM ( allowing for / using the Dependency Injection ), and the Job will be launched.

    /Anatoly
    Humans are stateful and mutable beings that have no problems processing many things concurrently and share state with others + they are usually "coupled"

Tags for this Thread

Posting Permissions

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