ClassNotFoundException: Hibernate Validator cannot find ScriptException in Karaf container

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ClassNotFoundException: Hibernate Validator cannot find ScriptException in Karaf container

MikeNow
This post has NOT been accepted by the mailing list yet.
Hibernate-Validator cannot find the ScriptException class in a Karaf container and throws ClassNotFoundException. I have tried to create Validator in many ways:

https://github.com/hibernate/hibernate-validator/blob/5.4/osgi/integrationtest/src/test/java/org/hibernate/validator/osgi/integrationtest/OsgiIntegrationTest.java

and

http://www.jasonday.net/content/jsr-303-bean-validation-and-spring-mvc-sling-osgi-container

Every time when ScriptException must be thrown I get this error:

    Caused by: java.lang.ClassNotFoundException: javax.script.ScriptException not found by org.hibernate.validator [202]

I added javax.script import to the pom.xml Import-Package element and
am using proper set of bundles from the hibernate-validator features file:

https://github.com/hibernate/hibernate-validator/blob/5.4/osgi/karaf-features/src/main/features/features.xml 

The code which causes exception in the validate method:

    public class ValidatorBean {
   
   
     public class ValidatorBean {
   
   
        @Getter
        private final Validator validator;
   
        ValidatorBean() {
            validator = Validation.byProvider(HibernateValidator.class)
                    .providerResolver(new MyValidationProviderResolver())
                    .configure()
                    .externalClassLoader(getClass().getClassLoader())
                    .buildValidatorFactory().getValidator();
        }
   
        public void validate(Object obj) {
            Set<ConstraintViolation<Object>> constraints = validator.validate(obj, Default.class, KRDCheck.class,
                    InfoMonitorCheck.class);
            if (!constraints.isEmpty()) {
                throw new ConstraintViolationException(constraints);
            }
        }
   
        // from : https://github.com/hibernate/hibernate-validator/blob/5.4/osgi/integrationtest/src/test/java/org/hibernate/validator/osgi/integrationtest/OsgiIntegrationTest.java
        // and: https://stackoverflow.com/questions/44349772/javax-validation-cant-find-hibernate-validator-in-karaf
        public static class MyValidationProviderResolver implements ValidationProviderResolver {
   
            @Override
            public List<ValidationProvider<?>> getValidationProviders() {
                return Collections.<ValidationProvider<?>>singletonList(new HibernateValidator());
            }
        }
    }

Loading...