Jersey服务器使用可运行的jar运行

时间:2016-04-30 19:17:49

标签: java jersey httpserver

我使用Jersey编写了一个示例HTTPServer。当我通过eclipse启动时它工作正常。我用Postman测试了。

我构建了一个可运行的jar并试图启动它,我收到以下错误并且服务器没有启动。请告诉我这里缺少的东西。

       SEVERE: The provider class, class com.sun.jersey.server.impl.model.parameter.mul
tivalued.JAXBStringReaderProviders$RootElementProvider, could not be instantiate
d. Processing will continue but the class will not be utilized
java.lang.IllegalArgumentException: argument type mismatch
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at com.sun.jersey.core.spi.component.ComponentConstructor._getInstance(C
omponentConstructor.java:210)
        at com.sun.jersey.core.spi.component.ComponentConstructor.getInstance(Co
mponentConstructor.java:180)
        at com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvi
der(ProviderFactory.java:166)
        at com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvide
r(ProviderFactory.java:137)
        at com.sun.jersey.core.spi.component.ProviderServices.getComponent(Provi
derServices.java:283)
        at com.sun.jersey.core.spi.component.ProviderServices.getProvidersAndSer
vices(ProviderServices.java:176)
        at com.sun.jersey.server.impl.model.parameter.multivalued.StringReaderFa
ctory.init(StringReaderFactory.java:60)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(W
ebApplicationImpl.java:1341)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(
WebApplicationImpl.java:180)
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApp
licationImpl.java:799)
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApp
licationImpl.java:795)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(We
bApplicationImpl.java:795)
        at com.sun.jersey.api.container.ContainerFactory.createContainer(Contain
erFactory.java:172)
        at com.sun.jersey.api.container.ContainerFactory.createContainer(Contain
erFactory.java:134)
        at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(Http
ServerFactory.java:172)


May 01, 2016 12:42:04 AM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/o
r provider classes:
  SEVERE: Missing dependency for constructor public com.sun.jersey.server.impl.m
odel.parameter.multivalued.JAXBStringReaderProviders$RootElementProvider(com.sun
.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
Exception in thread "main" com.sun.jersey.spi.inject.Errors$ErrorMessagesExcepti
on
        at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170
)
        at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(We
bApplicationImpl.java:795)
        at com.sun.jersey.api.container.ContainerFactory.createContainer(Contain
erFactory.java:172)
        at com.sun.jersey.api.container.ContainerFactory.createContainer(Contain
erFactory.java:134)
        at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(Http
ServerFactory.java:172)

我的主要方法如下:

public static void main( String[] args ) throws Exception {
        if ( args.length != 2 ) {
            logger.fatal( "Please pass port and config file path. " );
            System.exit( 1 );
        }

        port = Integer.parseInt( args[0].trim() );
        startServer();
        logger.info( "Started server successfully on port --> " + port );
    }

    private static void startServer() throws Exception {
        URI uri = UriBuilder.fromUri( "http://localhost/" ).port( port ).build();
        ResourceConfig rc = new PackagesResourceConfig( "my.test.apihandlers" );
        HttpServer server = HttpServerFactory.create( uri, rc );

        server.start();
    }

0 个答案:

没有答案