JEE 无法运行 JAX-RS WebService 框架应用程序

JEE can#39;t run JAX-RS WebService skeleton app(JEE 无法运行 JAX-RS WebService 框架应用程序)

本文介绍了JEE 无法运行 JAX-RS WebService 框架应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Windows、NetBeans 8.0.2、GlassFish 4.1.我无法让我的示例 JAX-RS 应用程序运行.

I'm using Windows, NetBeans 8.0.2, GlassFish 4.1. I can't make my example JAX-RS app running.

这是 pom.xml:

This is pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.wld</groupId>
    <artifactId>HelloWebService</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>HelloWebService</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.metro</groupId>
            <artifactId>webservices-rt</artifactId>
            <version>2.3</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>HelloWebService</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

和 web.xml:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Restful Web Application</display-name>
    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>
            com.sun.jersey.spi.container.servlet.ServletContainer
        </servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.wld.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

这是我的控制台输出:

NetBeans: Deploying on GlassFish Server 4.1
    profile mode: false
    debug mode: false
    force redeploy: true
Starting GlassFish Server 4.1
GlassFish Server 4.1 is running.
In-place deployment at C:Users	omasz.ducinLearningHelloWebService	argetHelloWebService
GlassFish Server 4.1, deploy, null, false
cd C:Users	omasz.ducinLearningHelloWebService; "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_31" cmd /c """C:\Program Files\NetBeans 8.0.2\java\maven\bin\mvn.bat" -Dnetbeans.deploy=true -Dmaven.ext.class.path=C:\Users\tomasz.ducin\AppData\Roaming\NetBeans\8.0.2\maven-nblib\netbeans-eventspy.jar -Dfile.encoding=UTF-8 package""
Scanning for projects...

------------------------------------------------------------------------
Building HelloWebService 1.0-SNAPSHOT
------------------------------------------------------------------------

--- maven-resources-plugin:2.5:resources (default-resources) @ HelloWebService ---
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
Copying 0 resource

--- maven-compiler-plugin:2.3.2:compile (default-compile) @ HelloWebService ---
Nothing to compile - all classes are up to date

--- maven-resources-plugin:2.5:testResources (default-testResources) @ HelloWebService ---
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:Users	omasz.ducinLearningHelloWebServicesrc	est
esources

--- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ HelloWebService ---
No sources to compile

--- maven-surefire-plugin:2.10:test (default-test) @ HelloWebService ---
Surefire report directory: C:Users	omasz.ducinLearningHelloWebService	argetsurefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0


--- maven-war-plugin:2.6:war (default-war) @ HelloWebService ---
Packaging webapp
Assembling webapp [HelloWebService] in [C:Users	omasz.ducinLearningHelloWebService	argetHelloWebService]
Processing war project
Copying webapp resources [C:Users	omasz.ducinLearningHelloWebServicesrcmainwebapp]
Webapp assembled in [60 msecs]
Building war: C:Users	omasz.ducinLearningHelloWebService	argetHelloWebService.war
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 3.109s
Finished at: Sat May 30 14:53:50 CEST 2015
Final Memory: 11M/245M
------------------------------------------------------------------------
NetBeans: Deploying on GlassFish Server 4.1
    profile mode: false
    debug mode: false
    force redeploy: true
In-place deployment at C:Users	omasz.ducinLearningHelloWebService	argetHelloWebService
GlassFish Server 4.1, deploy, null, false

如您所见,只有一个 java 文件.没有资源,没有测试,没有测试资源.无论如何,GLassFish 无法为该应用程序提供服务.我一直在网上寻找,但找不到原因.我正在考虑一些与 Windows 相关的事情,例如端口、防火墙或任何其他操作系统的东西.

As you can see, there is only one java file. No resources, no tests, no test resources. Anyway, GLassFish fails to serve the app. I've been looking in the web, but can't find the reason. I'm thinking about some Windows-related things, such as ports, firewalls or any other OS stuff.

下面是 glassfish 控制台输出:

Below is glassfish console output:

Launching GlassFish on Felix platform
maj 30, 2015 2:53:34 PM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner createBundleProvisioner
INFO: Create bundle provisioner class = class com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner.
maj 30, 2015 2:53:34 PM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner$DefaultCustomizer getLocations
WARNING: Skipping entry  because it is not an absolute URI.
maj 30, 2015 2:53:34 PM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner$DefaultCustomizer getLocations
WARNING: Skipping entry  because it is not an absolute URI.
Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishRuntime@d21e255 in service registry.
Found populator: com.sun.enterprise.v3.server.GFDomainXml
#!## LogManagerService.postConstruct : rootFolder=C:Program Filesglassfish-4.1glassfish
#!## LogManagerService.postConstruct : templateDir=C:Program Filesglassfish-4.1glassfishlib	emplates
#!## LogManagerService.postConstruct : src=C:Program Filesglassfish-4.1glassfishlib	emplateslogging.properties
#!## LogManagerService.postConstruct : dest=C:Users	omasz.ducinAppDataRoamingNetBeans8.0.2configGF_4.1domain1configlogging.properties
Info:   Running GlassFish Version: GlassFish Server Open Source Edition  4.1  (build 13)
Info:   Server log file is using Formatter class: com.sun.enterprise.server.logging.ODLLogFormatter
Info:   Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Info:   Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Info:   Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
Info:   Authorization Service has successfully initialized.
Info:   Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
Info:   Grizzly Framework 2.3.15 started in: 312ms - bound to [/0.0.0.0:8080]
Info:   Grizzly Framework 2.3.15 started in: 0ms - bound to [/0.0.0.0:8181]
Info:   Grizzly Framework 2.3.15 started in: 10ms - bound to [/0.0.0.0:4848]
Info:   Grizzly Framework 2.3.15 started in: 5ms - bound to [/0.0.0.0:3700]
Info:   GlassFish Server Open Source Edition  4.1  (13) startup time : Felix (2 138ms), startup services(1 647ms), total(3 785ms)
Info:   Grizzly Framework 2.3.15 started in: 26ms - bound to [/0.0.0.0:7676]
Info:   Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl@109d724c as OSGi service registration: org.apache.felix.framework.ServiceRegistrationImpl@4ba89729.
Info:   JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://WAWLT548.global.ad:8686/jndi/rmi://WAWLT548.global.ad:8686/jmxrmi
Info:   HV000001: Hibernate Validator 5.0.0.Final
Info:   Grizzly Framework 2.3.15 started in: 2ms - bound to [/0.0.0.0:8181]
Info:   Grizzly Framework 2.3.15 started in: 13ms - bound to [/0.0.0.0:8080]
Info:   visiting unvisited references
Info:   Java security manager is disabled.
Info:   Entering Security Startup Service.
Info:   Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
Info:   Security Service(s) started successfully.
Info:   Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080
Info:   Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181
Info:   Created HTTP listener admin-listener on host/port 0.0.0.0:4848
Info:   Created virtual server server
Info:   Created virtual server __asadmin
Info:   Setting JAAS app name glassfish-web
Info:   Virtual server server loaded default web module 
Warning:   Ignore WEB-INF/sun-web.xml in archive /C:/Users/tomasz.ducin/Learning/HelloWebService/target/HelloWebService/, as WLS counterpart runtime xml WEB-INF/glassfish-web.xml is present in the same archive.
Info:   Scanning for root resource and provider classes in the packages:
  com.wld.rest
Info:   Root resource classes found:
  class com.wld.rest.HelloService
Info:   No provider classes found.
Info:   Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
Severe:   WebModule[/HelloWebService]StandardWrapper.Throwable
com.sun.jersey.api.container.ContainerException: Unable to create resource
    at com.sun.jersey.server.impl.resource.SingletonFactory$Singleton.init(SingletonFactory.java:139)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$10.f(WebApplicationImpl.java:584)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    [...]
    at com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:179)
    at com.sun.jersey.server.impl.resource.SingletonFactory$Singleton.init(SingletonFactory.java:137)
    ... 74 more
Caused by: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:198)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:395)
    [...]
    at com.sun.jersey.server.impl.wadl.WadlApplicationContextImpl.getApplication(WadlApplicationContextImpl.java:79)
    at com.sun.jersey.server.impl.wadl.WadlResource.<init>(WadlResource.java:77)
    ... 81 more

Severe:   WebModule[/HelloWebService]Servlet /HelloWebService threw load() exception
java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:198)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:395)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Severe:   Startup of context /HelloWebService failed due to previous errors
Severe:   ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5954)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5712)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5946)
    ... 49 more
Caused by: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:198)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:395)
    [...]
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5704)
    ... 50 more

Warning:   java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1044)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Severe:   Exception while invoking class com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:168)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Severe:   Exception during lifecycle processing
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:168)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Severe:   Exception while loading the app
Severe:   Undeployment failed for context /HelloWebService
Severe:   Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
Info:   visiting unvisited references
Warning:   Ignore WEB-INF/sun-web.xml in archive /C:/Users/tomasz.ducin/Learning/HelloWebService/target/HelloWebService/, as WLS counterpart runtime xml WEB-INF/glassfish-web.xml is present in the same archive.
Info:   Scanning for root resource and provider classes in the packages:
  com.wld.rest
Info:   Root resource classes found:
  class com.wld.rest.HelloService
Info:   No provider classes found.
Info:   Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
Severe:   WebModule[/HelloWebService]StandardWrapper.Throwable
com.sun.jersey.api.container.ContainerException: Unable to create resource
    at com.sun.jersey.server.impl.resource.SingletonFactory$Singleton.init(SingletonFactory.java:139)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$10.f(WebApplicationImpl.java:584)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:198)
    at com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:179)
    at com.sun.jersey.server.impl.resource.SingletonFactory$Singleton.init(SingletonFactory.java:137)
    ... 74 more
Caused by: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:198)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:395)
    at com.sun.jersey.server.wadl.WadlBuilder.generateMethod(WadlBuilder.java:164)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResource(WadlBuilder.java:331)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResource(WadlBuilder.java:269)
    at com.sun.jersey.server.wadl.WadlBuilder.generate(WadlBuilder.java:105)
    at com.sun.jersey.server.impl.wadl.WadlApplicationContextImpl.getApplication(WadlApplicationContextImpl.java:79)
    at com.sun.jersey.server.impl.wadl.WadlResource.<init>(WadlResource.java:77)
    ... 81 more

Severe:   WebModule[/HelloWebService]Servlet /HelloWebService threw load() exception
java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:198)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:395)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Severe:   Startup of context /HelloWebService failed due to previous errors
Severe:   ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5954)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5712)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5946)
    ... 49 more
Caused by: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.jersey.server.wadl.WadlGeneratorImpl.createResponse(WadlGeneratorImpl.java:198)
    at com.sun.jersey.server.wadl.WadlBuilder.generateResponse(WadlBuilder.java:395)
    [...]
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5704)
    ... 50 more

Warning:   java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1044)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Severe:   Exception while invoking class com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:168)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Severe:   Exception during lifecycle processing
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:168)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
    [...]
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

Severe:   Exception while loading the app
Severe:   Undeployment failed for context /HelloWebService
Severe:   Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.sun.research.ws.wadl.Response.getRepresentationOrFault()Ljava/util/List;

我已经尝试清理、构建、使用 deps 构建、重新启动 IDE 几次但没有任何效果.不知道该怎么办.

I've tried cleaning, building, building with deps, restarting the IDE several times with no effect. Don't know what to do with it.

推荐答案

Glassfish 4 使用 Jersey 2.x.您应该相应地更改依赖项和 web.xml 配置.对于依赖,你可以使用

Glassfish 4 uses Jersey 2.x. You should change the dependency and web.xml configuration accordingly. For the dependency, you can use

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>${jersey2.version}</version>
    <scope>provided</scope>
</dependency>

和配置

<servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.wld.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

最近看到很多人(使用 Glassfish 和 Jersey)的一个问题"是 Glassfish 使用的是旧版本的 Jersey(旧的 2.x 版本).目前最新的是2.17.Glassfish 使用了与 2.x 系列中的第一个类似的东西.因此,新功能似乎存在一些兼容性问题.

One "gotcha" a see a lot of people (who are using Glassfish and Jersey) lately is the fact that Glassfish uses an older version of Jersey (old in the sense of an older 2.x version). The latest as of now is 2.17. Glassfish uses something near the first one in the 2.x family. So there seems to be some compatibility problems with new features.

我肯定会研究的一件事是 在 GlassFish 4 中更新 Jersey 2.这是一篇相当不错的文章.对于简单的启动应用程序,您可能不会遇到任何问题,但是对于新功能,尝试在 Glassfish 中升级 Jersey 可能会有所帮助.

One thing I would definitely look into is Updating Jersey 2 in GlassFish 4. It's a pretty good article. You may not face any issues will simple startup apps, but with new features, trying to upgrade Jersey in Glassfish might help.

还有一件事,记得摆脱你的 Jersey 1.x 依赖项.两者完全不相容.还要注意 Maven 依赖项中的 provided 范围.由于 Glassfish 已经内置了 Jersey,所以我们只是使用内部依赖项.

Another thing, remember to get rid of your Jersey 1.x dependencies. The two are completely incompatible. Also notice the provided scope in the Maven dependency. Since Glassfish has Jersey built in already, we are just using the internal dependencies.

Jersey 2.x Documentation

哦,还有一件事.Jersey 有一个原型,可以帮助您轻松入门.在 Netbeans 中就可以了

Oh and one other thing. Jersey has an archetype that helps you get started easily. In Netbeans just do

  1. 新项目
  2. Maven →Archetype 的项目
  3. 搜索 jersey-quickstart-webapp
  4. 选择组 ID org.glassfish.jersey.archetypes
  5. 的那个
  6. 应显示最新版本.

这篇关于JEE 无法运行 JAX-RS WebService 框架应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:JEE 无法运行 JAX-RS WebService 框架应用程序

基础教程推荐