Glassfish 无法找到/实例化 Jersey WebApplicationProviderImpl

发布于 2024-10-03 21:17:20 字数 1670 浏览 1 评论 0原文

我正在尝试使用 Glassfish 上的 Jersey(内置)创建 REST 服务。我安装了 GlassFish Server 开源版 3.0.1(内部版本 22)。这是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    <servlet>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

但是,当我尝试部署 WAR 时,我得到以下信息:

java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [com.sun.jersey.server.impl.container.WebApplicationProviderImpl], because it has not yet been started, or was already stopped
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1367)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at com.sun.jersey.core.reflection.ReflectionHelper.classForNameWithException(ReflectionHelper.java:236)
    at com.sun.jersey.spi.service.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:851)

那么我能做什么?它看起来像是一个类路径问题,但这都是 glassfish 内部的问题。

我还尝试将 Glassfish 中的 Jersey 组件更新为 1.4,如此处< /a>,但没有变化。

I'm trying to create REST services using Jersey (builtin) on Glassfish. I installed GlassFish Server Open Source Edition 3.0.1 (build 22). This is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    <servlet>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

However, when I try to deploy the WAR, I get this:

java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [com.sun.jersey.server.impl.container.WebApplicationProviderImpl], because it has not yet been started, or was already stopped
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1367)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at com.sun.jersey.core.reflection.ReflectionHelper.classForNameWithException(ReflectionHelper.java:236)
    at com.sun.jersey.spi.service.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:851)

So what can I do? It looks like a classpath issue, but this is all deep inside glassfish.

I also tried updating the Jersey component in Glassfish to 1.4 as described here, but no change.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖彼岸 2024-10-10 21:17:20

查看我博客中的以下示例,它可能会有所帮助:

我的 web.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    <persistence-context-ref>
        <persistence-context-ref-name>persistence/em</persistence-context-ref-name>
        <persistence-unit-name>CustomerService</persistence-unit-name>
    </persistence-context-ref>
</web-app>

Check out the following example from my blog, it may help:

My web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    <persistence-context-ref>
        <persistence-context-ref-name>persistence/em</persistence-context-ref-name>
        <persistence-unit-name>CustomerService</persistence-unit-name>
    </persistence-context-ref>
</web-app>
我喜欢麦丽素 2024-10-10 21:17:20

我自己已经找到了问题的原因。显然,如果您将 JAR 文件部署为 Web 应用程序,即使您明确选择了类型,Glassfish 也会感到非常困惑。我唯一要做的就是将文件后缀更改为 WAR,并且它起作用了(一开始出现了不同的错误,但更容易找到解决方案)。

I've found the cause of the problem myself. Apparently, Glassfish gets deeply confused if you deploy a JAR file as a web app, even if you explicitly select the type. The only thing I had to do is change the file suffix to WAR, and it worked (got a different error at first, but one that was much easier to find a solution for).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文