I get an error in Eclipse while trying a simple example with the JCommander package. The error says:
The attribute validateWith is undefined for the annotation type Parameter
and the code I'm using is the following:
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import com.beust.jcommander.*;
import com.beust.jcommander.validators.PositiveInteger;
public class JCommanderExample {
@Parameter(names = { "-sp", "-semAndPrec"}, validateWith = CorrectPathValidator.class)
private Path semAndPrec;
}
Of course I have provided the CorrectPathValidator class as described in the documentation at http://jcommander.org/#Parameter_validation.
Here is the class:
import java.nio.file.Paths;
import com.beust.jcommander.IParameterValidator;
import com.beust.jcommander.ParameterException;
public class CorrectPathValidator implements IParameterValidator {
public void validate(String name, String value) throws ParameterException {
try {
Paths.get(value);
} catch (Exception e) {
String error = "Parameter " + name + " should be a path (found "
+ value + ")";
throw new ParameterException(error);
}
}
}
Apparently I'm missing something, but the example at http://jcommander.org/#Parameter_validation appears to be identical to what I tried:
@Parameter(names = "-age", validateWith = PositiveInteger.class)
private Integer age;
Can someone please tell me why I get the error?