在 Apache Felix 中无法访问基于 Vaadin 的 Web 应用程序 (404)

发布于 2024-12-03 23:17:23 字数 3988 浏览 0 评论 0原文

更新:已解决。我必须使用实用程序包在 OSGI 中自动加载 Vaadin 应用程序。请参阅http://dev.vaadin.com/wiki/Arvue/OSGi 我使用的包:org.vaadin.osgi、org.vaadin.osgi.staticres

===

我创建了一个示例 Vaadin 项目,使用 Maven + BND 将其构建为 OSGI 包。

使用我的“webui-1.0.jar”包及其依赖的“vaadin-6.6.6.jar”启动 Apache Felix。 我可以访问 localhost:8080,但 localhost:8080/webui 显示 “访问 /webui 时出现问题。原因:NOT_FOUND”。

“webui-1.0.jar”包含:

com   -- java classes
META-INF/MANIFEST.MF
VAADIN  -- empty now, but will contain Vaadin widgetsets and other resources
WEB-INF/web.xml

我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>webui</display-name>
    <context-param>
        <description>
        Vaadin production mode</description>
        <param-name>productionMode</param-name>
        <param-value>false</param-value>
    </context-param>
    <servlet>
        <servlet-name>Vaadin1 Application</servlet-name>
        <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
        <init-param>
            <description>
            Vaadin application class to start</description>
            <param-name>application</param-name>
            <param-value>com.mywebtest.MyVaadinApplication</param-value>
        </init-param>
        <init-param>
            <description>
            Application widgetset</description>
            <param-name>widgetset</param-name>
            <param-value>com.mywebtest.widgetset.Vaadin1Widgetset</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>Vaadin1 Application</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

我的 Maven + BND 生成的 MANIFEST.MF 文件:

Manifest-Version: 1
Bnd-LastModified: 1315684875698
Build-Jdk: 1.6.0_26
Built-By: ask
Bundle-ManifestVersion: 2
Bundle-Name: webui
Bundle-SymbolicName: webui
Bundle-Version: 1.0.0
Class-Path: 
Created-By: Apache Maven Bundle Plugin
Export-Package: com.mywebtest;uses:="com.vaadin,com.vaadin.ui";version="
 1.0.0"
Import-Package: com.vaadin,com.vaadin.ui
Tool: Bnd-1.43.0

运行包:

g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (3.2.2)
    1|Active     |    1|Apache Felix Bundle Repository (1.6.6)
    2|Active     |    1|Apache Felix Configuration Admin Service (1.2.8)
    3|Active     |    1|Apache Felix Dependency Manager (3.0.0)
    4|Active     |    1|Apache Felix Gogo Command (0.8.0)
    5|Active     |    1|Apache Felix Gogo Runtime (0.8.0)
    6|Active     |    1|Apache Felix Gogo Shell (0.8.0)
    7|Active     |    1|Apache Felix Http Api (2.2.0)
    8|Active     |    1|Apache Felix Http Jetty (2.2.0)
    9|Active     |    1|Apache Felix Metatype Service (1.0.4)
   10|Active     |    1|Apache Felix Declarative Services (1.6.0)
   11|Active     |    1|Apache Felix Web Management Console (3.1.8)
   12|Active     |    1|Vaadin (6.6.6)
   13|Active     |    1|webui (1.0.0)

UPDATE: SOLVED. I had to use a utility bundle to auto-load Vaadin apps in OSGI. See http://dev.vaadin.com/wiki/Arvue/OSGi
The bundles I used: org.vaadin.osgi, org.vaadin.osgi.staticres

===

I created a sample Vaadin project, built it with Maven + BND to as an OSGI bundle.

started Apache Felix with my "webui-1.0.jar" bundle along with its dependent "vaadin-6.6.6.jar".
I can access localhost:8080, but localhost:8080/webui shows
"Problem accessing /webui. Reason: NOT_FOUND".

"webui-1.0.jar" contains:

com   -- java classes
META-INF/MANIFEST.MF
VAADIN  -- empty now, but will contain Vaadin widgetsets and other resources
WEB-INF/web.xml

my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>webui</display-name>
    <context-param>
        <description>
        Vaadin production mode</description>
        <param-name>productionMode</param-name>
        <param-value>false</param-value>
    </context-param>
    <servlet>
        <servlet-name>Vaadin1 Application</servlet-name>
        <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
        <init-param>
            <description>
            Vaadin application class to start</description>
            <param-name>application</param-name>
            <param-value>com.mywebtest.MyVaadinApplication</param-value>
        </init-param>
        <init-param>
            <description>
            Application widgetset</description>
            <param-name>widgetset</param-name>
            <param-value>com.mywebtest.widgetset.Vaadin1Widgetset</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>Vaadin1 Application</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

my MANIFEST.MF file generated by Maven + BND:

Manifest-Version: 1
Bnd-LastModified: 1315684875698
Build-Jdk: 1.6.0_26
Built-By: ask
Bundle-ManifestVersion: 2
Bundle-Name: webui
Bundle-SymbolicName: webui
Bundle-Version: 1.0.0
Class-Path: 
Created-By: Apache Maven Bundle Plugin
Export-Package: com.mywebtest;uses:="com.vaadin,com.vaadin.ui";version="
 1.0.0"
Import-Package: com.vaadin,com.vaadin.ui
Tool: Bnd-1.43.0

Running bundles:

g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (3.2.2)
    1|Active     |    1|Apache Felix Bundle Repository (1.6.6)
    2|Active     |    1|Apache Felix Configuration Admin Service (1.2.8)
    3|Active     |    1|Apache Felix Dependency Manager (3.0.0)
    4|Active     |    1|Apache Felix Gogo Command (0.8.0)
    5|Active     |    1|Apache Felix Gogo Runtime (0.8.0)
    6|Active     |    1|Apache Felix Gogo Shell (0.8.0)
    7|Active     |    1|Apache Felix Http Api (2.2.0)
    8|Active     |    1|Apache Felix Http Jetty (2.2.0)
    9|Active     |    1|Apache Felix Metatype Service (1.0.4)
   10|Active     |    1|Apache Felix Declarative Services (1.6.0)
   11|Active     |    1|Apache Felix Web Management Console (3.1.8)
   12|Active     |    1|Vaadin (6.6.6)
   13|Active     |    1|webui (1.0.0)

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

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

发布评论

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

评论(1

极度宠爱 2024-12-10 23:17:23

您运行时中的所有捆绑包都不会自动为您注册 Web 端点,因为您在捆绑包中编写了一个名为 web.xml 的文件。

在 OSGi 中发布 Web 应用程序有两个主要选项。第一个是获取 HttpService 服务的实例,您应该发现它是由“Felix Http Jetty”包发布的。

第二种更接近“传统”Java Web 应用程序开发,是构建“Web 应用程序包”或 WAB。这基本上是一个像您的包一样的WEB-INF/web.xml。不过,您需要做 2 件额外的事情才能使其正常工作:

  • 在 MANIFEST.MF 中声明 Web 应用程序,如下所示: Web-ContextPath: /webui
  • 安装提供 WAB 支持的包,例如由 PAX Web 提供。

None of the bundles you have in your runtime are going to automatically register a web endpoint for you, just because you wrote a file inside your bundle called web.xml.

You have two main options for publishing web applications in OSGi. The first is to obtain an instance of the HttpService service, which you should find is published by the "Felix Http Jetty" bundle.

The second, which is closer to "traditional" Java web app development, is to build a "Web Application Bundle" or WAB. This is basically a bundle like yours with a WEB-INF/web.xml. You will need to do 2 extra things for it to work though:

  • Declare the web application in your MANIFEST.MF like this: Web-ContextPath: /webui
  • Install a bundle that provides WAB support, such as the one provided by PAX Web.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文