我的项目中存在对com / fasterxml / jackson / databind / jsonschema / SchemaAware的依赖。我使用gradle和dropwizard db迁移构建了一个fatJar,会出现以下错误。
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/jsonschema/SchemaAware
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:450)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:366)
at io.dropwizard.jackson.Jackson.newObjectMapper(Jackson.java:19)
at io.dropwizard.setup.Bootstrap.<init>(Bootstrap.java:61)
at io.dropwizard.Application.run(Application.java:67)
at com.flipkart.birbal.BirbalApplication.main(BirbalApplication.java:29)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.jsonschema.SchemaAware
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 30 more
fatJar引用了com / fasterxml / jackson / databind / jsonSchema / SchemaAware.class。因此,jsonSchema中存在CaSe差异。
build.gradle
dependencies {
compile(
'io.dropwizard:dropwizard-core:' + dropwizardVersion,
'io.dropwizard:dropwizard-jdbi:' + dropwizardVersion,
'io.dropwizard:dropwizard-hibernate:' + dropwizardVersion,
'io.dropwizard:dropwizard-migrations:' + dropwizardVersion,
'io.dropwizard:dropwizard-testing:' + dropwizardVersion,
'org.codehaus.groovy:groovy-all:' + groovyVersion,
'org.projectlombok:lombok:' + lombokVersion,
'mysql:mysql-connector-java:' + mysqlConnectorVersion,
'org.mongodb.morphia:morphia:' + morphiaVersion,
'commons-net:commons-net:' + commonsNetVersion,
'com.google.inject:guice:' + guiceVersion,
'commons-threadpool:commons-threadpool:' + commonsThreadpoolVersion,
'org.apache.commons:commons-lang3:' + commonsLang3Version,
'com.hubspot.dropwizard:dropwizard-guice:' + dropWizardGuiceVersion,
'net.sf.opencsv:opencsv:' + opencsvVersion,
'io.federecio:dropwizard-swagger:' + swaggerVersion,
'org.mockftpserver:MockFtpServer:' + mockFtpServerVersion,
'commons-io:commons-io:' + commonsIoVersion,
'org.codehaus.gpars:gpars:' + gparsVersion,
'org.gperfutils:gprof:' + gperfVersion,
'com.googlecode.json-simple:json-simple:' + jsonSimpleVersion
)
testCompile group: 'junit', name: 'junit', version: '4.+'
}
gradle.properties
dropwizardVersion=0.7.1
groovyVersion=2.3.6
lombokVersion=1.12.4
guiceVersion=3.0
commonsThreadpoolVersion=20030513.073905
dropWizardGuiceVersion=0.7.1
commonsLang3Version=3.3.1
mysqlConnectorVersion=5.1.28
commonsNetVersion=3.3
opencsvVersion=2.3
morphiaVersion=0.108
swaggerVersion=0.5.2
mockFtpServerVersion=2.4
commonsIoVersion=2.4
gparsVersion=1.2.1
gperfVersion=0.3.0-groovy-2.3
jsonSimpleVersion=1.1
这是因为依赖于Swagger。 Swagger引入了jackson-module-jsonSchema,其中包含com.fasterxml.jackson.databind.jsonSchema包,它没有SchemaAware类。 SchemaAware类可以在com.fasterxml.jackson.databind.jsonschema(jackson-databind)中找到。
如何解决此冲突?