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

Thread: How do I use CommandLineJobRunner?

  1. #11
    Join Date
    Jun 2011
    Posts
    25

    Default

    So, I read up on maven and created a few sample apps with it. So, how would I have maven automatically fetch these jars for me? I don't know what libraries and versions to use, so how would maven figure this out?

    Also, the jobRepository. I'm simply following a tutorial at http://java.dzone.com/news/spring-batch-hello-world-1. I am doing this completely blind, in the dark. Only vaguely understand each part, here. Am I supposed to have a jobRepository class that I can edit? I don't have one, so I don't know about those ambiguous constructors. I'd think this tutorial would have correct data and I'm assuming if it's not building then it's something I did wrong.

  2. #12
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    you can try this: https://github.com/acogoluegnes/Spring-Batch-Workshop

    there's an hello world example. You need an IDE with Maven support (download SpringSource Tool Suite for example, which is based on Eclipse). You can then import the workshop as Maven projects and follow the TODOs.

  3. #13
    Join Date
    Jun 2011
    Posts
    25

    Unhappy

    Thanks, I downloaded SpringSource Tool Suite. Then I imported the hello-world-start maven project into it and loaded it up.

    I noticed the Spring-Batch-Workshop project says, in the README, "The concepts are (quickly) covered in the PDF file at the root of this project. The PDF contains additional instructions and hints to work on the projects." There are no PDFs in the project. So I really already feel discouraged here.

    It was able to compile fine, but I can't figure out how to get it to run. I tried configuring my build according to ( http://victor-jan.blogspot.com/2010/...ng-spring.html )--that is, created a new Run Configuration to run:

    Code:
    org.springframework.batch.core.launch.support.CommandLineJobRunner hello-world-job.xml HelloWorldTasklet time=11:06AM
    The error upon building is this:

    Code:
    14:01:10.001 [main] INFO  o.s.c.s.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@defa1a: startup date [Thu Jun 23 14:01:09 EDT 2011]; root of context hierarchy
    14:01:10.093 [main] INFO  o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [hello-world-job.xml]
    14:01:10.119 [main] DEBUG o.s.b.f.xml.DefaultDocumentLoader - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
    14:01:10.163 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Loading schema mappings from [META-INF/spring.schemas]
    14:01:10.168 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Loaded schema mappings: {http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd, 
    ...
    14:01:10.171 [main] DEBUG o.s.b.f.xml.PluggableSchemaResolver - Found XML schema [http://www.springframework.org/schema/beans/spring-beans-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-3.0.xsd
    14:01:10.244 [main] DEBUG o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Loading bean definitions
    14:01:10.276 [main] DEBUG o.s.b.f.xml.XmlBeanDefinitionReader - Loaded 3 bean definitions from location pattern [hello-world-job.xml]
    14:01:10.276 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@defa1a: org.springframework.beans.factory.support.DefaultListableBeanFactory@1a9334: defining beans [transactionManager,jobRepository,jobLauncher]; root of factory hierarchy
    14:01:10.313 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@bd928a]
    14:01:10.322 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@5a9de6]
    14:01:10.323 [main] INFO  o.s.b.f.s.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a9334: defining beans [transactionManager,jobRepository,jobLauncher]; root of factory hierarchy
    14:01:10.324 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'transactionManager'
    14:01:10.324 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'transactionManager'
    14:01:10.368 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'transactionManager' to allow for resolving potential circular references
    14:01:10.370 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'transactionManager'
    14:01:10.370 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'jobRepository'
    14:01:10.370 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'jobRepository'
    14:01:10.377 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'jobRepository' to allow for resolving potential circular references
    14:01:10.377 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'jobRepository'
    14:01:10.405 [main] DEBUG o.s.t.i.NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
    14:01:10.405 [main] DEBUG o.s.t.i.NameMatchTransactionAttributeSource - Adding transactional method [create*] with attribute [PROPAGATION_REQUIRES_NEW,ISOLATION_SERIALIZABLE]
    14:01:10.406 [main] DEBUG o.s.t.i.NameMatchTransactionAttributeSource - Adding transactional method [getLastJobExecution*] with attribute [PROPAGATION_REQUIRES_NEW,ISOLATION_SERIALIZABLE]
    14:01:10.435 [main] DEBUG o.s.aop.framework.JdkDynamicAopProxy - Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [java.util.concurrent.ConcurrentHashMap@5f8172]
    14:01:10.464 [main] DEBUG o.s.aop.framework.JdkDynamicAopProxy - Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [java.util.concurrent.ConcurrentHashMap@87c268]
    14:01:10.465 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'jobRepository'
    14:01:10.466 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'jobLauncher'
    14:01:10.467 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'jobLauncher'
    14:01:10.470 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'jobLauncher' to allow for resolving potential circular references
    14:01:10.490 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'jobRepository'
    14:01:10.491 [main] DEBUG o.s.aop.framework.JdkDynamicAopProxy - Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [org.springframework.batch.core.repository.support.SimpleJobRepository@ba8602]
    14:01:10.519 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'jobLauncher'
    14:01:10.520 [main] INFO  o.s.b.c.l.support.SimpleJobLauncher - No TaskExecutor has been set, defaulting to synchronous executor.
    14:01:10.521 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'jobLauncher'
    14:01:10.523 [main] DEBUG o.s.c.s.ClassPathXmlApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@176e552]
    14:01:10.523 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
    14:01:10.532 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'jobRepository'
    14:01:10.533 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Autowiring by type from bean name 'org.springframework.batch.core.launch.support.CommandLineJobRunner' via property 'jobRepository' to bean named 'jobRepository'
    14:01:10.533 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'jobLauncher'
    14:01:10.533 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Autowiring by type from bean name 'org.springframework.batch.core.launch.support.CommandLineJobRunner' via property 'launcher' to bean named 'jobLauncher'
    14:01:10.547 [main] ERROR o.s.b.c.l.s.CommandLineJobRunner - Job Terminated in error: No bean named 'HelloWorldTasklet' is defined
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'HelloWorldTasklet' is defined
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075) ~[spring-context-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:339) [spring-batch-core-2.1.7.RELEASE.jar:na]
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) [spring-batch-core-2.1.7.RELEASE.jar:na]
    14:01:10.548 [main] INFO  o.s.c.s.ClassPathXmlApplicationContext - Closing org.springframework.context.support.ClassPathXmlApplicationContext@defa1a: startup date [Thu Jun 23 14:01:09 EDT 2011]; root of context hierarchy
    14:01:10.548 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
    14:01:10.548 [main] INFO  o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a9334: defining beans [transactionManager,jobRepository,jobLauncher]; root of factory hierarchy
    I just need a simple working Spring Batch project...every place I turn, exponentially more errors.

  4. #14
    Join Date
    Jun 2011
    Posts
    25

    Default

    Say I use this on the command line. I've done the following:

    Code:
    $ git clone git://github.com/acogoluegnes/Spring-Batch-Workshop.git
    $ cd Spring-Batch-Workshop
    $ cd hello-world-solution
    $ mvn package
    Which worked fine. And mvn test passes successfully, so I know something's working here.

    How would I be able to take the HelloWorldTasklet.class, and all dependencies, and put them into an isolated folder where I can demonstrate usage of CommandLineJobRunner? If I need maven then I'll use it, but I'm trying to move this to a non-build-environment. In the end, this is all I wish to do and if I could do this without errors, I'd be able to figure out a lot more on my own.

  5. #15
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    ok, first, the README also says that the PDF file is in the "presentation" directory (in the very first sentence). This PDF file helps you understand the concepts, not really how to launch Java programs from the command line.

    second, Java programs are always tricky to run from the command line :-)

    the "mvn package" command should have created a hello-world-solution-1.0.0.jar file in "target". Copy this JAR in a working directory.

    then, go back in the "hello-world-solution" directory and launch the following command: "mvn dependency:copy-dependencies". It copies all the dependencies you need in the "target/dependency" directory. Copy all these JAR files in the working directory.

    Then go to the working directory and launch the following command: java -classpath "./*" org.springframework.batch.core.launch.support.Comm andLineJobRunner hello-world-job.xml helloWorldJob

    you should see some logging output but also the "hello world".

  6. #16
    Join Date
    Jun 2011
    Posts
    25

    Wink

    Thank you, arno!!!!!!!! It was a long day(s) for me, I'm relieved to finally see "Hello World".

    Your suggestion of mvn dependency:copy-dependencies is immensely useful, now I know to just type that if I really need to extract all dependencies.

    With a working directory of :
    Code:
    hello-world-job.xml
    aopalliance-1.0.jar
    commons-io-1.4.jar
    commons-lang-2.6.jar
    commons-logging-1.1.1.jar
    h2-1.3.154.jar
    hello-world-solution-1.0.0.jar
    jcl-over-slf4j-1.6.1.jar
    jettison-1.1.jar
    junit-4.8.2.jar
    logback-classic-0.9.28.jar
    logback-core-0.9.28.jar
    slf4j-api-1.6.1.jar
    spring-aop-3.0.5.RELEASE.jar
    spring-asm-3.0.5.RELEASE.jar
    spring-batch-core-2.1.7.RELEASE.jar
    spring-batch-infrastructure-2.1.7.RELEASE.jar
    spring-beans-3.0.5.RELEASE.jar
    spring-context-3.0.5.RELEASE.jar
    spring-core-3.0.5.RELEASE.jar
    spring-expression-3.0.5.RELEASE.jar
    spring-jdbc-3.0.5.RELEASE.jar
    spring-test-3.0.5.RELEASE.jar
    spring-tx-3.0.5.RELEASE.jar
    xpp3_min-1.1.4c.jar
    xstream-1.3.jar
    I typed:
    Code:
    java -classpath "./*" org.springframework.batch.core.launch.support.CommandLineJobRunner hello-world-job.xml helloWorldJob
    And, like you said, I got a LOT of logging output (167 lines...btw is there a way to turn off this logging?). One of them was "Hello world!". I can't tell you how much this helps, thanks a lot!

  7. #17
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    for the logging, you can copy the logback-test.xml file in src/test/resources to src/main/resources and rename it logback.xml. Then package again, copy the hello-world-1.0.0.jar to the working, and try.

    packaging and launching a Java program is a pain if you're not used to (especially with the dependencies). This isn't a Spring Batch problem actually. When developing Spring Batch jobs, you should stay inside your IDE, and package everything up only for integration testing and production.

  8. #18
    Join Date
    Jun 2011
    Posts
    25

    Default

    Bleh, my IDE is usually console and vi.

    One last question while on the topic: is there a way I can take the hello-world-solution maven project, and move it to its own independent maven project. It seems dependent on the others, here's its pom.xml:

    Code:
    <?xml version="1.0"?>
    <project
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
            xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                    <artifactId>springbatch</artifactId>
                    <groupId>com.zenika.workshop</groupId>
                    <version>1.0.0</version>
            </parent>
            <artifactId>hello-world-solution</artifactId>
    
    </project>
    Any kind of magical maven command that creates a new project and a new pom.xml that doesn't depend on the parent?

  9. #19
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    Bleh, my IDE is usually console and vi.
    good luck for Java development then!

    One last question while on the topic: is there a way I can take the hello-world-solution maven project, and move it to its own independent maven project. It seems dependent on the others, here's its pom.xml:

    Code:
    <?xml version="1.0"?>
    <project
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
            xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                    <artifactId>springbatch</artifactId>
                    <groupId>com.zenika.workshop</groupId>
                    <version>1.0.0</version>
            </parent>
            <artifactId>hello-world-solution</artifactId>
    
    </project>
    Any kind of magical maven command that creates a new project and a new pom.xml that doesn't depend on the parent?
    there's no magic command for this. The parent POM declares the dependencies and as you can see, the POM for the hello world project is quite empty. Welcome to the Maven world!

  10. #20
    Join Date
    Jun 2011
    Posts
    25

    Default

    So, I can't create a hello-world-solution that's its own project, without needing to be a subproject of Spring-Batch-Workshop?

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
  •