使用雅加达而不是javax的Dropwizard
Dropwizard using jakarta not javax
我目前正在 java 使用框架 Dropwizard 开发网络服务。
对于其余 API 界面,我使用的是 JAX-RS
。由于我需要使用 POST-Request 上传文件,因此我将 jersey-media-multipart
添加到我的 Gradle 依赖项中。然而突然之间,intellij 无法解析 javax.ws.rs.*
导入语句,而是更新的 jakarta.ws.rs
,因此我将接口更改为 jakarta
。现在的问题是 Dropwizard 显然仍然需要 JAX-RS
所以我在堆栈跟踪中得到以下错误:
java.lang.NoClassDefFoundError: javax/ws/rs/QueryParam
at io.dropwizard.jersey.validation.JerseyParameterNameProvider.getParameterNameFromAnnotations(JerseyParameterNameProvider.java:46)
at io.dropwizard.jersey.validation.JerseyParameterNameProvider.getParameterNames(JerseyParameterNameProvider.java:35)
at org.hibernate.validator.internal.util.ExecutableParameterNameProvider.getParameterNames(ExecutableParameterNameProvider.java:37)
at org.hibernate.validator.internal.properties.javabean.JavaBeanExecutable.getParameterName(JavaBeanExecutable.java:86)
at org.hibernate.validator.internal.metadata.aggregated.ParameterMetaData$Builder.build(ParameterMetaData.java:165)
at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.findParameterMetaData(ExecutableMetaData.java:436)
at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.build(ExecutableMetaData.java:391)
at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataBuilder$BuilderDelegate.build(BeanMetaDataBuilder.java:260)
at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataBuilder.build(BeanMetaDataBuilder.java:133)
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.createBeanMetaData(BeanMetaDataManagerImpl.java:206)
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.getBeanMetaData(BeanMetaDataManagerImpl.java:165)
at org.hibernate.validator.internal.engine.ValidatorImpl.buildNewLocalExecutionContext(ValidatorImpl.java:772)
at org.hibernate.validator.internal.engine.ValidatorImpl.access0(ValidatorImpl.java:84)
at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.doValidate(ValidatorImpl.java:707)
at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.indexedValue(ValidatorImpl.java:681)
at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:26)
at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:16)
at org.hibernate.validator.internal.engine.valueextraction.ValueExtractorHelper.extractValues(ValueExtractorHelper.java:42)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedContainerElementsForCurrentGroup(ValidatorImpl.java:651)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:598)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:409)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedAnnotatedObjectForCurrentGroup(ValidatorImpl.java:629)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:590)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:409)
at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:172)
at io.dropwizard.configuration.BaseConfigurationFactory.validate(BaseConfigurationFactory.java:238)
at io.dropwizard.configuration.BaseConfigurationFactory.build(BaseConfigurationFactory.java:127)
at io.dropwizard.configuration.BaseConfigurationFactory.build(BaseConfigurationFactory.java:108)
at io.dropwizard.cli.ConfiguredCommand.parseConfiguration(ConfiguredCommand.java:128)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:74)
at io.dropwizard.cli.Cli.run(Cli.java:78)
at io.dropwizard.Application.run(Application.java:94)
at Application.main(Application.java:10)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.QueryParam
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.QueryParam
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 33 more
Execution failed for task ':Application.main()'.
> Process 'command '/usr/lib/jvm/java-13-openjdk/bin/java'' finished with non-zero exit value 1
我不知道我的 build.gradle
是否有助于解决我的问题,但这是我的依赖项:
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'application'
dependencies {
compile 'io.dropwizard:dropwizard-core:2.0.8'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-multipart', version: '3.0.0-M1'
}
mainClassName = 'Application'
run {
args = ['server']
}
我很无助,在 google 上搜索了很多关于 dropwizard 的信息,发现他们显然应该从版本 2.0.0 开始支持 jakarta。我目前使用的是 2.0.8 版,但仍然遇到这个内部错误。
我使用自己的 dropwizard 库 dropwizard-forms 而不是 jersey-media-multipart 修复了它。
我的新 gradle 依赖项现在看起来像这样:
dependencies {
compile group: 'io.dropwizard', name: 'dropwizard-core', version: '2.0.8'
compile 'io.dropwizard:dropwizard-forms:2.0.8'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
现在我也可以再次使用javax了,不需要切换到jakarta
我目前正在 java 使用框架 Dropwizard 开发网络服务。
对于其余 API 界面,我使用的是 JAX-RS
。由于我需要使用 POST-Request 上传文件,因此我将 jersey-media-multipart
添加到我的 Gradle 依赖项中。然而突然之间,intellij 无法解析 javax.ws.rs.*
导入语句,而是更新的 jakarta.ws.rs
,因此我将接口更改为 jakarta
。现在的问题是 Dropwizard 显然仍然需要 JAX-RS
所以我在堆栈跟踪中得到以下错误:
java.lang.NoClassDefFoundError: javax/ws/rs/QueryParam
at io.dropwizard.jersey.validation.JerseyParameterNameProvider.getParameterNameFromAnnotations(JerseyParameterNameProvider.java:46)
at io.dropwizard.jersey.validation.JerseyParameterNameProvider.getParameterNames(JerseyParameterNameProvider.java:35)
at org.hibernate.validator.internal.util.ExecutableParameterNameProvider.getParameterNames(ExecutableParameterNameProvider.java:37)
at org.hibernate.validator.internal.properties.javabean.JavaBeanExecutable.getParameterName(JavaBeanExecutable.java:86)
at org.hibernate.validator.internal.metadata.aggregated.ParameterMetaData$Builder.build(ParameterMetaData.java:165)
at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.findParameterMetaData(ExecutableMetaData.java:436)
at org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData$Builder.build(ExecutableMetaData.java:391)
at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataBuilder$BuilderDelegate.build(BeanMetaDataBuilder.java:260)
at org.hibernate.validator.internal.metadata.aggregated.BeanMetaDataBuilder.build(BeanMetaDataBuilder.java:133)
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.createBeanMetaData(BeanMetaDataManagerImpl.java:206)
at org.hibernate.validator.internal.metadata.BeanMetaDataManagerImpl.getBeanMetaData(BeanMetaDataManagerImpl.java:165)
at org.hibernate.validator.internal.engine.ValidatorImpl.buildNewLocalExecutionContext(ValidatorImpl.java:772)
at org.hibernate.validator.internal.engine.ValidatorImpl.access0(ValidatorImpl.java:84)
at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.doValidate(ValidatorImpl.java:707)
at org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.indexedValue(ValidatorImpl.java:681)
at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:26)
at org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues(ListValueExtractor.java:16)
at org.hibernate.validator.internal.engine.valueextraction.ValueExtractorHelper.extractValues(ValueExtractorHelper.java:42)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedContainerElementsForCurrentGroup(ValidatorImpl.java:651)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:598)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:409)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedAnnotatedObjectForCurrentGroup(ValidatorImpl.java:629)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:590)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:409)
at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:172)
at io.dropwizard.configuration.BaseConfigurationFactory.validate(BaseConfigurationFactory.java:238)
at io.dropwizard.configuration.BaseConfigurationFactory.build(BaseConfigurationFactory.java:127)
at io.dropwizard.configuration.BaseConfigurationFactory.build(BaseConfigurationFactory.java:108)
at io.dropwizard.cli.ConfiguredCommand.parseConfiguration(ConfiguredCommand.java:128)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:74)
at io.dropwizard.cli.Cli.run(Cli.java:78)
at io.dropwizard.Application.run(Application.java:94)
at Application.main(Application.java:10)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.QueryParam
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.QueryParam
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 33 more
Execution failed for task ':Application.main()'.
> Process 'command '/usr/lib/jvm/java-13-openjdk/bin/java'' finished with non-zero exit value 1
我不知道我的 build.gradle
是否有助于解决我的问题,但这是我的依赖项:
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'application'
dependencies {
compile 'io.dropwizard:dropwizard-core:2.0.8'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-multipart', version: '3.0.0-M1'
}
mainClassName = 'Application'
run {
args = ['server']
}
我很无助,在 google 上搜索了很多关于 dropwizard 的信息,发现他们显然应该从版本 2.0.0 开始支持 jakarta。我目前使用的是 2.0.8 版,但仍然遇到这个内部错误。
我使用自己的 dropwizard 库 dropwizard-forms 而不是 jersey-media-multipart 修复了它。 我的新 gradle 依赖项现在看起来像这样:
dependencies {
compile group: 'io.dropwizard', name: 'dropwizard-core', version: '2.0.8'
compile 'io.dropwizard:dropwizard-forms:2.0.8'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
现在我也可以再次使用javax了,不需要切换到jakarta