import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class CommandLineJobLauncher {
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: CommandLineJobLauncher <jobName>");
return;
}
String jobName = args[0];
ApplicationContext context = new ClassPathXmlApplicationContext("batch-config.xml");
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
Job job = context.getBean(jobName, Job.class);
if (job != null) {
try {
jobLauncher.run(job, new JobParametersBuilder().toJobParameters());
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("Job not found: " + jobName);
}
}
}
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme