Encountering javax.validation.ValidationException on a working project

3,498 views
Skip to first unread message

Vinay Pandey

unread,
Sep 17, 2014, 2:00:34 PM9/17/14
to dropwiz...@googlegroups.com
Hello folks,

I had a perfectly working project till a few weeks back, but all of a sudden I have started getting the following error:

java -jar target\api-core-1.0-SNAPSHOT.jar target\api-core-1.0-SNAPSHOT.jar server service-config.yml
Exception in thread "main" javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
        at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)
        at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)
        at io.dropwizard.setup.Bootstrap.<init>(Bootstrap.java:62)
        at io.dropwizard.Application.run(Application.java:67)
        at com.rms.rae.api.APIApplication.main(APIApplication.java:25)


I am using Dropwizard 0.7.1, and nothing on the internet has helped me so far. I have tried adding hibernate-validator explicitly. The funny thing is that when I run my project from IntelliJ Idea then I don't get any error, it's only when I call the java from command line is when I start getting this problem.

Any help/hint will be very useful to me.

Thanks!

Michael McCarthy

unread,
Sep 17, 2014, 2:18:39 PM9/17/14
to dropwiz...@googlegroups.com
Hi Vinay, would you mind pasting in your POM?

Thanks
Michael

Vinay Pandey

unread,
Sep 17, 2014, 2:23:23 PM9/17/14
to dropwiz...@googlegroups.com
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
    <artifactId>abc</artifactId>
    <groupId>com.xyz.pqr</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>api-core</artifactId>
    <packaging>jar</packaging>

    <name>API Core Library</name>

    <properties>
        <dropwizard.version>0.7.1</dropwizard.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.6.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-hibernatevalidator-provider</artifactId>
            <version>2.3.1.GA</version>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-auth</artifactId>
            <version>${dropwizard.version}</version>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-testing</artifactId>
            <version>${dropwizard.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>io.dropwizard</groupId>
                    <artifactId>dropwizard-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-servlet</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <!--Enable versioning-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <!--Enable Fat JAR-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <minimizeJar>true</minimizeJar>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.rms.rae.api.APIApplication</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>


--
You received this message because you are subscribed to a topic in the Google Groups "dropwizard-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dropwizard-user/daVL_uQO-EQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cemo

unread,
Sep 17, 2014, 2:28:48 PM9/17/14
to dropwiz...@googlegroups.com
Why do you need this?

Vinay Pandey

unread,
Sep 17, 2014, 2:33:24 PM9/17/14
to dropwiz...@googlegroups.com
I am sorry I have just been reading all over the place and people recommended adding many dependencies, and I have added many dependencies which I actually don't need but I felt may have removed this error.

Michael McCarthy

unread,
Sep 17, 2014, 2:33:30 PM9/17/14
to dropwiz...@googlegroups.com
I was wondering that too - Dropwizard is Jersey so I wouldn't expect any RESTeasy in there. I suspect what has happened is that you've added the wrong import in IntelliJ, and clicked the button when IntelliJ asks you if you want it on your classpath. So IntelliJ will have access to a library that Maven doesn't in the build.

Could you paste in the imports in the class where you have the validation?

Thanks

Vinay Pandey

unread,
Sep 17, 2014, 2:35:15 PM9/17/14
to dropwiz...@googlegroups.com
Also, I just ran the sample application which I had created based on the example presented in the Dropwizard site, that too was working perfectly and here is the error I get:

>java -jar target\pilotapi-1.0-SNAPSHOT-shaded.jar server database-config.yml
Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.hibernate.validator.internal.engine.ConfigurationImpl.<clinit>(ConfigurationImpl.java:66)
        at org.hibernate.validator.HibernateValidator.createSpecializedConfiguration(HibernateValidator.java:37)
        at org.hibernate.validator.HibernateValidator.createSpecializedConfiguration(HibernateValidator.java:34)
        at javax.validation.Validation$ProviderSpecificBootstrapImpl.configure(Validation.java:220)
        at io.dropwizard.setup.Bootstrap.<init>(Bootstrap.java:66)
        at io.dropwizard.Application.run(Application.java:67)
        at com.rms.pilotapi.PilotAPIApplication.main(PilotAPIApplication.java:23)
Caused by: java.lang.IllegalArgumentException: Invalid logger interface org.hibernate.validator.internal.util.logging.Log (implementation not found in sun.misc.Launcher$AppClassLoader@55f96302)
        at org.jboss.logging.Logger$1.run(Logger.java:2254)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2227)
        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2214)
        at org.hibernate.validator.internal.util.logging.LoggerFactory.make(LoggerFactory.java:29)
        at org.hibernate.validator.internal.util.Version.<clinit>(Version.java:27)
        ... 7 more

Vinay Pandey

unread,
Sep 17, 2014, 2:36:15 PM9/17/14
to dropwiz...@googlegroups.com
I must also emphasise that I am able to run these projects from IntelliJ itself, it's only when I run it from command line that I get the problem.

Michael McCarthy

unread,
Sep 17, 2014, 2:37:27 PM9/17/14
to dropwiz...@googlegroups.com
Could you paste in your custom config file if you have one and some of PilotAPIApplication?

Vinay Pandey

unread,
Sep 17, 2014, 2:38:43 PM9/17/14
to dropwiz...@googlegroups.com
I do not have any custom config files for any of the applications

Vinay Pandey

unread,
Sep 17, 2014, 2:40:02 PM9/17/14
to dropwiz...@googlegroups.com
This is the only Configuration I have for PilotAPI (I am sorry, I am new to Dropwizard so it may not be what you need)

public class APIConfiguration extends Configuration{
    @NotEmpty
    private String host = "localhost";

    @Valid
    private int port = 8080;

    @NotEmpty
    private String database = "pilotDb";

    public APIConfiguration() {
    }

    @JsonProperty
    public String getHost() {
        return host;
    }

    @JsonProperty
    public void setHost(String host) {
        this.host = host;
    }

    @JsonProperty
    public int getPort() {
        return port;
    }

    @JsonProperty
    public void setPort(int port) {
        this.port = port;
    }

    @JsonProperty
    public String getDatabase() {
        return database;
    }

    @JsonProperty
    public void setDatabase(String database) {
        this.database = database;
    }}

Michael McCarthy

unread,
Sep 17, 2014, 2:40:27 PM9/17/14
to dropwiz...@googlegroups.com
It looks like your logger is setup incorrectly as well, I would expect to see these imports:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

and for validation, ones that look like this:

import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

If you look at the dependencies, dropwizard-validator already includes hibernate-validator so no need for extra imports.

Vinay Pandey

unread,
Sep 17, 2014, 2:42:51 PM9/17/14
to dropwiz...@googlegroups.com
Should I add this in the configuration file? I am not using logger anywhere so far.

Michael McCarthy

unread,
Sep 17, 2014, 2:44:38 PM9/17/14
to dropwiz...@googlegroups.com
That's the custom config class I meant. Could you paste in the imports?

Vinay Pandey

unread,
Sep 17, 2014, 2:49:10 PM9/17/14
to dropwiz...@googlegroups.com
Here is the complete configuration file

package com.xyz.pqr.api;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.Valid;

Michael McCarthy

unread,
Sep 17, 2014, 2:57:24 PM9/17/14
to dropwiz...@googlegroups.com
Would you mind pasting the output of:

mvn clean compile

I'm trying to reproduce this now.

Thanks
Michael

Cemo

unread,
Sep 17, 2014, 2:57:56 PM9/17/14
to dropwiz...@googlegroups.com

On 17 September 2014 21:35, Vinay Pandey <babbu...@gmail.com> wrote:
Also, I just ran the sample application which I had created based on the example presented in the Dropwizard site, that too was working perfectly and here is the error I get:

Could you share your "mvn -version" ? 

Vinay Pandey

unread,
Sep 17, 2014, 3:00:32 PM9/17/14
to dropwiz...@googlegroups.com
mvn -version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T09:37:52-08:00)
Maven home: D:\Programs\Apache\apache-maven-3.2.1
Java version: 1.8.0_05, vendor: Oracle Corporation
Java home: D:\Programs\Java\jdk1.8.0_05\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"



mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building API Core Library 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ api-core ---
[INFO] Deleting D:\My Documents\IdeaProjects\xyz\pqr\api-core\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ api-core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ api-core ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to D:\My Documents\IdeaProjects\xyz\pqr\api-core\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.525 s
[INFO] Finished at: 2014-09-17T11:59:26-08:00
[INFO] Final Memory: 15M/583M
[INFO] --



--

Vinay Pandey

unread,
Sep 17, 2014, 3:03:03 PM9/17/14
to dropwiz...@googlegroups.com
Will it help if I attached my whole project?

Michael McCarthy

unread,
Sep 17, 2014, 3:03:39 PM9/17/14
to dropwiz...@googlegroups.com
I'm still stuck I must admit. Is there anything dropwizard related in your parent POM? Things that seemed a bit weird to me were the exclusions in the test dependency and the fact that it isn't test scoped...

Michael McCarthy

unread,
Sep 17, 2014, 3:04:22 PM9/17/14
to dropwiz...@googlegroups.com
Sure

Michael McCarthy

unread,
Sep 17, 2014, 3:07:16 PM9/17/14
to dropwiz...@googlegroups.com
mvn help:effective-pom might also help if anything is odd in the parent POM.

Cemo

unread,
Sep 17, 2014, 3:16:36 PM9/17/14
to dropwiz...@googlegroups.com

On 17 September 2014 22:03, Michael McCarthy <mikeycm...@gmail.com> wrote:
I'm still stuck I must admit. Is there anything dropwizard related in your parent POM? Things that seemed a bit weird to me were the exclusions in the test dependency and the fact that it isn't test scoped...

       
Could you replace 

   <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-testing</artifactId>
            <version>${dropwizard.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>io.dropwizard</groupId>
                    <artifactId>dropwizard-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-servlet</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

with this one:

       <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-testing</artifactId>
            <version>${dropwizard.version}</version>
            <scope>test</scope>
        </dependency>

Vinay Pandey

unread,
Sep 17, 2014, 3:17:14 PM9/17/14
to dropwiz...@googlegroups.com
Here are the files

--
effective-pom.txt
api-core.zip

Vinay Pandey

unread,
Sep 17, 2014, 3:22:33 PM9/17/14
to dropwiz...@googlegroups.com
@Cemo - I have already tried removing the exclusions, it does not help :(

Here is the output:
java -jar target\api-core-1.0-SNAPSHOT.jar server service-config.yml

Exception in thread "main" javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
        at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)
        at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)
        at io.dropwizard.setup.Bootstrap.<init>(Bootstrap.java:62)
        at io.dropwizard.Application.run(Application.java:67)
        at com.xyz.pqr.api.APIApplication.main(APIApplication.java:20)


api-core.zip

Michael McCarthy

unread,
Sep 17, 2014, 3:23:25 PM9/17/14
to dropwiz...@googlegroups.com
I can now reproduce that output with my own test.

Michael McCarthy

unread,
Sep 17, 2014, 3:38:13 PM9/17/14
to dropwiz...@googlegroups.com
Got it, the problem is the <minimizeJar>true</minimizeJar> bit that has been added to the shade plugin. Could you take that off and try?


On Wednesday, 17 September 2014 20:22:33 UTC+1, Vinay Pandey wrote:

Vinay Pandey

unread,
Sep 17, 2014, 3:44:30 PM9/17/14
to dropwiz...@googlegroups.com
This worked! Thanks a lot!


What I am curious about is that this tag had been there from the beginning and it was working earlier. I will do some research and find out what changed.

A big shout-out to Michael McCarthy for his help! You guys rock!

Vinay

Vinay Pandey

unread,
Sep 17, 2014, 5:03:40 PM9/17/14
to dropwiz...@googlegroups.com
And I apologise for forgetting to thank Cemo, thank you Cemo! :)

Lance N.

unread,
Sep 17, 2014, 10:05:06 PM9/17/14
to dropwiz...@googlegroups.com
From what I can tell <minimizeJar> means "limit to directly declared dependencies". That is, if the program dynamically loads classes based on a string or class scanning, <minimizeJar> rips out those classes. This is not a good idea for any modern fancy ten-thousand-packages Java app. 

Also, different packages store important resources at the top level, and if two jars use the same file name, shading picks one of the files and drops the other. The other jar will fail because its resource file is bogus.

On Wednesday, September 17, 2014 11:00:34 AM UTC-7, Vinay Pandey wrote:
Hello folks,

I had a perfectly working project till a few weeks back, but all of a sudden I have started getting the following error:

java -jar target\api-core-1.0-SNAPSHOT.jar target\api-core-1.0-SNAPSHOT.jar server service-config.yml

Exception in thread "main" javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
        at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)
        at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)
        at io.dropwizard.setup.Bootstrap.<init>(Bootstrap.java:62)
        at io.dropwizard.Application.run(Application.java:67)
        at com.rms.rae.api.APIApplication.main(APIApplication.java:25)


I am using Dropwizard 0.7.1, and nothing on the internet has helped me so far. I have tried adding hibernate-validator explicitly. The funny thing is that when I run my project from IntelliJ Idea then I don't get any error, it's only when I call the java from command line is when I start getting this problem.

Any help/hint will be very useful to me.

Thanks!

Vinay Pandey

unread,
Sep 18, 2014, 1:29:00 AM9/18/14
to dropwizard-user
So shading is an improper technique for building fat jars? is there any other way to make them?

--

Tatu Saloranta

unread,
Sep 18, 2014, 12:04:54 PM9/18/14
to dropwiz...@googlegroups.com
No, shading is fine, but minimization won't work because big apps/services tend to use more dynamic classloading.

And using non-namespaces main-level resources is a bad idea in general; even if they were not dropped, resource-loader would be load arbitrary choice.

-+ Tatu +-


--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.

Lance N.

unread,
Sep 18, 2014, 8:38:40 PM9/18/14
to dropwiz...@googlegroups.com
Hm. I thought that the java classloader used the jar as the first namespace. So, if two jars use the same file name, if the jars are separate each will get the right file. I'll have to study that again.

Vinay Pandey

unread,
Sep 19, 2014, 2:59:01 PM9/19/14
to dropwizard-user
Even I am confused now, because I was thinking the same thing. That's why I was excluding out the duplicate jars. I am not only new to dropwizard, but also relatively new to JAVA as well, will really appreciate if you can let me know about this. Here is one resource I came across: http://javarevisited.blogspot.com/2012/12/how-classloader-works-in-java.html
Reply all
Reply to author
Forward
0 new messages