简体   繁体   English

如何在Karaf中获得Jetty来从文件系统提供静态内容?

[英]How to get Jetty in Karaf to serve static content from file system?

I need to serve static content from outside a bundle in Karaf. 我需要从Karaf中的捆绑包外部提供静态内容。 Since it already has Pax Web and Jetty built in, I've thought it wouldn't be a problem, but no success so far :( 由于它已经内置了Pax Web和Jetty,所以我认为这不是问题,但到目前为止没有成功:(

I have jetty , http , http-whiteboard and war features installed. 我安装了jettyhttphttp-whiteboardwar功能。 Following http://team.ops4j.org/wiki/display/paxweb/Advanced+Jetty+Configuration , I've added this to etc/jetty.xml : 按照http://team.ops4j.org/wiki/display/paxweb/Advanced+Jetty+Configuration ,我已将其添加到etc/jetty.xml

<Get name="handler">
    <Call name="addHandler">
        <Arg>
            <New class="org.eclipse.jetty.servlet.ServletContextHandler">
                <Set name="contextPath">/app</Set>
                <Set name="resourceBase">/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki/
                </Set>
                <Call name="addServlet">
                    <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
                    <Arg>/</Arg>
                </Call>
            </New>
        </Arg>
    </Call>
</Get>

The complete file is: 完整的文件是:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//
DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

<Configure class="org.eclipse.jetty.server.Server">

    <!-- =========================================================== -->
    <!-- Set connectors -->
    <!-- =========================================================== -->
    <!-- One of each type! -->
    <!-- =========================================================== -->

    <!-- Use this connector for many frequently idle connections and for threadless 
        continuations. -->
    <Call name="addConnector">
        <Arg>
            <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
                <Set name="host">
                    <Property name="jetty.host" default="0.0.0.0" />
                </Set>
                <Set name="port">
                    <Property name="jetty.port" default="8282" />
                </Set>
                <Set name="maxIdleTime">300000</Set>
                <Set name="Acceptors">2</Set>
                <Set name="statsOn">false</Set>
                <Set name="confidentialPort">8443</Set>
                <Set name="lowResourcesConnections">20000</Set>
                <Set name="lowResourcesMaxIdleTime">5000</Set>
            </New>
        </Arg>
    </Call>

    <!-- =========================================================== -->
    <!-- Configure Authentication Realms -->
    <!-- Realms may be configured for the entire server here, or -->
    <!-- they can be configured for a specific web app in a context -->
    <!-- configuration (see $(jetty.home)/contexts/test.xml for an -->
    <!-- example). -->
    <!-- =========================================================== -->
    <Call name="addBean">
        <Arg>
            <New class="org.eclipse.jetty.plus.jaas.JAASLoginService">
                <Set name="name">karaf</Set>
                <Set name="loginModuleName">karaf</Set>
                <Set name="roleClassNames">
                    <Array type="java.lang.String">
                        <Item>org.apache.karaf.jaas.modules.RolePrincipal</Item>
                    </Array>
                </Set>
            </New>
        </Arg>
    </Call>
    <Call name="addBean">
        <Arg>
            <New class="org.eclipse.jetty.plus.jaas.JAASLoginService">
                <Set name="name">default</Set>
                <Set name="loginModuleName">karaf</Set>
                <Set name="roleClassNames">
                    <Array type="java.lang.String">
                        <Item>org.apache.karaf.jaas.modules.RolePrincipal</Item>
                    </Array>
                </Set>
            </New>
        </Arg>
    </Call>


    <Get name="handler">
        <Call name="addHandler">
            <Arg>
                <New class="org.eclipse.jetty.servlet.ServletContextHandler">
                    <Set name="contextPath">/app</Set>
                    <Set name="resourceBase">/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki
                    </Set>
                    <Call name="addServlet">
                        <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
                        <Arg>/</Arg>
                    </Call>
                </New>
            </Arg>
        </Call>
    </Get>

</Configure>

And created the file org.ops4j.pax.web.cfg with this content: 并使用以下内容创建了文件org.ops4j.pax.web.cfg

org.ops4j.pax.web.config.file=/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.karaf.launcher/etc/jetty.xml

In the log I see 在日志中,我看到了

2012-06-02 12:03:52,800 | INFO  | g.ops4j.pax.web) | Server                           |  -  -  | jetty-7.5.4.v20111024
2012-06-02 12:03:52,848 | INFO  | g.ops4j.pax.web) | ContextHandler                   |  -  -  | started o.e.j.s.ServletContextHandler{/app,file:/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki/}
2012-06-02 12:03:52,907 | INFO  | g.ops4j.pax.web) | AbstractConnector                |  -  -  | Started SelectChannelConnector@0.0.0.0:8282 STARTING
2012-06-02 12:03:52,914 | INFO  | g.ops4j.pax.web) | JettyServerImpl                  | 124 - org.ops4j.pax.web.pax-web-jetty - 1.0.9 | Pax Web available at [0.0.0.0]:[8080]
2012-06-02 12:03:52,927 | INFO  | g.ops4j.pax.web) | AbstractConnector                |  -  -  | Started NIOSocketConnectorWrapper@0.0.0.0:8080 STARTING

But the files aren't visible. 但是文件不可见。 Eg, I have a file /home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki/.style , but going to either http://192.168.1.9:8080/app/.style or http://192.168.1.9:8282/app/.style gives 404 error. 例如,我有一个文件/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki/.style ,但是转到http://192.168.1.9:8080/app/.stylehttp://192.168.1.9:8282/app/.style给出404错误。

A bit late, perhaps, but.. 也许有点晚,但是..

Doing the same thing worked well for me, ie i copied the code snippet from http://team.ops4j.org/wiki/display/paxweb/Advanced+Jetty+Configuration and changed the two paths. 对我来说,做同样的事情很好,例如,我从http://team.ops4j.org/wiki/display/paxweb/Advanced+Jetty+Configuration复制了代码片段,并更改了两条路径。 I restarted karaf and my files were served. 我重新启动karaf,并且文件已送达​​。

Are you running karaf as a user that has access to /home/aromanov? 您是否以有权访问/ home / aromanov的用户身份运行karaf?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM