Announcement Announcement Module
Collapse
No announcement yet.
Does Command line batch require Spring container? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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, 10:44 AM.

    Comment


    • #3
      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

      Comment

      Working...
      X