It is possible to control a maven build with JobScheduler.

Assume you have a simple java project controlled by Maven. The build should start every day at 2 a.m. followed by the execution of the previously built project.

Create a Job called maven_build

Select Shell as language and put the following code into the textbox:

 cd %SCHEDULER_DATA%\config\live\Maven
 mvn clean compile exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args="simpleJob.xml simpleJob"


Select Run Time|Everyday and specify a single start at 2 a.m.


Running the job it will produce some output like this:
 

 2011-11-02 02:00:54.043 [info]   SCHEDULER-918  state=starting (at=2011-11-02 02:00:54.012)
 2011-11-02 02:00:54.043 [info]   SCHEDULER-987  Starting process: "C:\Windows\TEMP\\sosBBAD.cmd"
 2011-11-02 02:00:55.525 [info]    
 2011-11-02 02:00:55.525 [info]   C:\ProgramData\sos-berlin.com\jobscheduler\scheduler-1.3.12.1296>cd C:/ProgramData/sos-berlin.com/jobscheduler/scheduler-1.3.12.1296\config\live\Maven  
 2011-11-02 02:00:55.525 [info]    
 2011-11-02 02:00:55.525 [info]   C:\ProgramData\sos-berlin.com\jobscheduler\scheduler-1.3.12.1296\config\live\Maven>mvn clean compile exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args="simpleJob.xml simpleJob" 
 2011-11-02 02:01:05.010 [info]   [INFO] Scanning for projects... 
 2011-11-02 02:01:05.010 [info]   [INFO] Searching repository for plugin with prefix: 'exec'. 
 2011-11-02 02:01:05.010 [info]   [INFO] ------------------------------------------------------------------------ 
 2011-11-02 02:01:05.010 [info]   [INFO] Building Spring Batch Hello World 
 2011-11-02 02:01:05.010 [info]   [INFO]    task-segment: [clean, compile, exec:java] 
 2011-11-02 02:01:05.010 [info]   [INFO] ------------------------------------------------------------------------ 
 2011-11-02 02:01:05.010 [info]   [INFO] [clean:clean \{execution: default-clean\}] 
 2011-11-02 02:01:05.010 [info]   [INFO] [resources:resources \{execution: default-resources\}] 
 2011-11-02 02:01:05.010 [info]   [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
 2011-11-02 02:01:05.010 [info]   [INFO] Copying 3 resources 
 2011-11-02 02:01:05.010 [info]   [INFO] [compiler:compile \{execution: default-compile\}] 
 2011-11-02 02:01:05.010 [info]   [INFO] Compiling 1 source file to C:\ProgramData\sos-berlin.com\jobscheduler\scheduler-1.3.12.1296\config\live\Maven\target\classes 
 2011-11-02 02:01:05.010 [info]   [INFO] Preparing exec:java 
 2011-11-02 02:01:05.010 [info]   [INFO] No goals needed for project - skipping 
 2011-11-02 02:01:05.010 [info]   [INFO] [exec:java \{execution: default-cli\}]
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:03 org.springframework.context.support.AbstractApplicationContext prepareRefresh 
 2011-11-02 02:01:05.026 [info]   INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1e91a4d: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1e91a4d]; startup date [Wed Nov 02 02:01:03 CET 2011]; root of context hierarchy 
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:03 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
 2011-11-02 02:01:05.026 [info]   INFO: Loading XML bean definitions from class path resource [simpleJob.xml] 
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:04 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
 2011-11-02 02:01:05.026 [info]   INFO: Loading XML bean definitions from class path resource [applicationContext.xml] 
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:04 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory 
 2011-11-02 02:01:05.026 [info]   INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@1e91a4d]: org.springframework.beans.factory.support.DefaultListableBeanFactory@19cc1b 
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:04 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 
 2011-11-02 02:01:05.026 [info]   INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@19cc1b: defining beans [jobLauncher,jobRepository,hello,space,world,taskletStep,simpleJob]; root of factory hierarchy 
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:04 org.springframework.batch.core.launch.support.SimpleJobLauncher afterPropertiesSet 
 2011-11-02 02:01:05.026 [info]   INFO: No TaskExecutor has been set, defaulting to synchronous executor. 
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:04 org.springframework.batch.core.launch.support.SimpleJobLauncher$1 run 
 2011-11-02 02:01:05.026 [info]   INFO: Job: [SimpleJob: [name=simpleJob]] launched with the following parameters: [\{\}\{\}\{\}\{\}] 
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:04 org.springframework.batch.core.launch.support.SimpleJobLauncher$1 run 
 2011-11-02 02:01:05.026 [info]   INFO: Job: [SimpleJob: [name=simpleJob]] completed successfully with the following parameters: [\{\}\{\}\{\}\{\}] 
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:04 org.springframework.context.support.AbstractApplicationContext doClose 
 2011-11-02 02:01:05.026 [info]   INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@1e91a4d: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1e91a4d]; startup date [Wed Nov 02 02:01:03 CET 2011]; root of context hierarchy 
 2011-11-02 02:01:05.026 [info]   02.11.2011 02:01:04 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons 
 2011-11-02 02:01:05.026 [info]   INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@19cc1b: defining beans [jobLauncher,jobRepository,hello,space,world,taskletStep,simpleJob]; root of factory hierarchy
 2011-11-02 02:01:05.026 [info]   Hello World!
 2011-11-02 02:01:05.041 [info]   SCHEDULER-915  Process event

Related Downloads

  • sample_maven.zip
    To make this example run, put the code into your live folder. Note that the source code of your project is stored in the same folder as the job.