1

I'm reading a spring batch book and making the examples that show because I will start to work with java and spring batch the next month(now I use c#), one example uses ParameterValidator to validate receiving one parameter name so the maven test will work only if the parameter it was past,

 public class ParameterValidator implements JobParametersValidator {
        @Override
        public void validate(JobParameters parameters) throws JobParametersInvalidException {
        String fileName = parameters.getString("fileName");
        if(!StringUtils.hasText(fileName)) {
            throw new JobParametersInvalidException("fileName missing");
        }
        else if(!StringUtils.endsWithIgnoreCase(fileName, "csv")) {
            throw new JobParametersInvalidException("fileName parameter does " +
                    "not use the csv file extension");
        }
    }

I tried passing the data using arguments tag in pom.xml:

     <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
            <arguments> fileName=foo.csv</arguments>
            </configuration>
        </plugin>
    </plugins>

, editing the test:

test configuration maven

and try other answers I found on internet but always raise the error of missing parameter.

Is it possible to pass arguments using this IDE and maven?

Thanks!

Sandeep Kumar
  • 2,397
  • 5
  • 30
  • 37
Cris
  • 15
  • 5
  • Does this answer your question? [How do I set JobParameters in spring batch with spring-boot](https://stackoverflow.com/questions/21557623/how-do-i-set-jobparameters-in-spring-batch-with-spring-boot) – Andrey Dec 23 '19 at 09:20
  • I know how to pass parameters when I have a .jar file from cmd, but when I run the lyfecycle in the ide I can't go beyond the test because it gives me an error and I can't create it. `java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: java.lang.IllegalStateException: Failed to execute CommandLineRunner Caused by: org.springframework.batch.core.JobParametersInvalidException: fileName missing` I guess there must be a way either by editing the test run on the lifecycle or through pom.xml to pass a parameter but I can't find it – Cris Dec 23 '19 at 11:49

1 Answers1

-1

You can just pass in command line argument through args[] passed to main function and call CommandLineJobRunner.main(args) as if you are executing from cmd

Felix Stanley
  • 73
  • 1
  • 10