I tied using the liquibase maven plugin (with intellij) for generating diff between database Schema and the hibernate mapping files in the application. I struggled hard to get past the error “Could not Fine hibernate.cfg.xml” File.
I checked that the file was in the class path and Maven-Liquibase-Plugin was able to see it in its class-loaders classpath. (i debugged and verified in org.liquibase.maven.plugins.LiquibaseDatabaseDiff getMavenArtifactClassLoader method). But the resource was not visible to the hibernate environment.
Hibernate finds the resource using its org.hibernate.util.ConfigHelper which checks for this resource in current Thread’s context class loader , ConfigHelper.class’s class loader and finally thru system classLoader but none of these loaders were able to find the resource.
To fix this i tried setting the mavenArtifactClassLoader as current Thread’s contextClassLoader in org.liquibase.maven.plugins.LiquibaseDatabaseDiff
Line:97 cl = getMavenArtifactClassLoader();
This fixed my problem.
Please can you suggest if there was any other better way i could have resolved this ? Can we use this fix in the maven-liquibase-plugin project ?