提问者:小点点

Dropwizard使用jakarta而不是javax


我目前正在使用框架Dropwizard在java开发一个网络服务。对于RestAPI界面,我使用的是JAX-RS。由于我需要使用POST-Request上传文件,我将jersey-media-multipart添加到我的Gradle依赖项中。然而突然间intellij无法解析javax.ws.rs。*import语句,但更新的jakarta.ws.rs,因此我将界面更改为jakarta。现在的问题是Dropwizard显然仍然需要JAX-RS,所以我得到了以下stacktrace错误:

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.access$200(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']
}

我很无助,谷歌了很多关于dropwizard的信息,发现他们显然应该从2.0.0版开始支持jakarta。我目前正在使用2.0.8版,但仍然得到这个内部bug。


共1个答案

匿名用户

我使用自己的dropwizard库dropwizard-form而不是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。