我需要从 Karaf 的捆绑包之外提供静态内容。由于它已经内置了 Pax Web 和 Jetty,我认为这不是问题,但到目前为止还没有成功:(
我已安装jetty
、http
和功能。在http://team.ops4j.org/wiki/display/paxweb/Advanced+Jetty+Configuration之后,我将其添加到:http-whiteboard
war
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>
完整的文件是:
<?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>
并使用以下内容创建了文件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
在我看到的日志中
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
但文件不可见。例如,我有一个文件,/home/aromanov/workspaces/odp-server/ru.focusmedia.odp.server.poim.resources-rodniki/.style
但是会出现404 错误。http://192.168.1.9:8080/app/.style
http://192.168.1.9:8282/app/.style