Reputation: 4474
I have a Spring Batch process that writes a .txt file. It works great, except for one thing. When it runs on a scheduler (zena), the output file gets written out to the wrong location because I have the path set up to be relative. Here's how I specify the location of the output file in the FlatFileItemWriter:
FlatFileItemWriter<Something> writer = new FlatFileItemWriter<Something>();
writer.setResource(new FileSystemResource(new File("..csv/output.txt")));
When I run without the scheduler, the file is written out to the correct directory:
/BatchJob/csv/output.txt
But when I run on the scheduler, the file gets written out to:
/Scheduler/Location/csv/output.txt
I tried using classPathResource:
writer.setResource(new ClassPathResource("output.txt", getClass()));
But then it tries to write the file to a directory location based on the name of the class package. Instead, I want to write the file to a specific directory path location, not based on the package name.
Upvotes: 1
Views: 1802
Reputation: 21923
Read the Directory parameter from a property file and inject into your resource.
Upvotes: 2