在jetty中部署静态内容

问题描述 投票:0回答:1

我正在尝试在jetty中部署app static,但是使用xml配置文件,因为我正在使用虚拟主机。

我为deploy创建了这个文件xml:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" 
  "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/mail</Set>
    <!--<Call name="setInitParameter">
        <Arg>org.eclipse.jetty.servlet.Default.useFileMappedBuffer</Arg>
        <Arg>false</Arg>
    </Call> -->
    <Set name="handler">
    <New class="org.eclipse.jetty.server.handler.ResourceHandler">
      <Set name="resourceBase">/ccmail</Set>
      <Set name="directoriesListed">true</Set>
    </New>
  </Set>

    <Set name="virtualHosts">
    <Array type="java.lang.String">
      <Item>apps.cairunet.ad.br</Item>     
    </Array>
  </Set> 

</Configure>

我的文件夹应用程序的名称是ccmail。位于webapps/ccmail我已经尝试通过路径:

<Set name="resourceBase">/ccmail</Set>

<Set name="resourceBase">ccmail</Set>

<Set name="resourceBase">./ccmail</Set>

<Set name="resourceBase">webapps/ccmail</Set>

<Set name="resourceBase">/webapps/ccmail</Set>

任何这条路都不适合我。

Jetty发布此错误:

2019-02-25 09:36:46.422:警告:oejs.ServletContextHandler:main:ServletContextHandler.setHandler不应该被调用。使用insertHandler或setSessionHandler等.2011-02-25 09:36:46.484:警告:oejw.WebInfConfiguration:main:无法生成resourceBase作为webapp tmp dir名称的一部分:java.lang.IllegalStateException:没有为资源库或war设置context 2019-02-25 09:36:46.500:WARN:oejw.WebAppContext:main:上下文启动失败oejwWebAppContext @ 7d0587f1 {/ mail,nul

l,UNAVAILABLE,apps.cairunet.ad.br} java.lang.IllegalStateException:org.eclipse.jetty上的org.eclipse.jetty.webapp.WebInfConfiguration.unpack(WebInfConfiguration.java:577)中的上下文没有设置resourceBase或war org.eclipse.jetty.webapp.WebAppContext.doStart上的org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:506)中的.webapp.WebInfConfiguration.preConfigure(WebInfConfiguration.java:152)(WebAppContext.java:544 )org.eclipse.jetty.uart.start(AbstractLifeCycle.java:68)中的org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:46)org.eclipse.jetty上的org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)。在org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:151)的org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:505)上部署.AppLifeCycle.runBindings(AppLifeCycle.java:192)在org.eclipse.jetty.devloy.providers.We上的org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180)位于org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610)的org.eclipse.jetty.deploy.providers.ScanningAppProvider $ 1.fileAdded(ScanningAppProvider.java:64)中的bAppProvider.fileAdded(WebAppProvider.java:453) )org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529)org.eclipse.jet.util.Scanner.scan(Scanner.java:392)atg.eclipse.jetty.util.Scanner。在org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150)的org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)上的doStart(Scanner.java:313) org.eclipse.jetty.util.compart.AbstractLifeCycle.start(AbstractLifeCycle.java:68)位于org.eclipse.jet.deploy.DeploymentManager的org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:579) .doStart(DeploymentManager.java:240)位于org.eclipse.jetty.uart.start(AbstractLifeCycle.java:68)org.eclipse.jetty.util.component.ContainerLifeCycle.start(Containe)的org.eclipse.jetty.util.component(AbstractLifeCycle.java:68) rLifeCycle.java:138)org.eclipse.jet.Server.start(Server.java:415)org.eclipse.jet.上一个org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)位于org.eclipse.jetty.util.component.AbstractLifeCycle.start的org.eclipse.jetty.server.Server.doStart(Server.java:382)的.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) (AbstractLifeCycle.java:68)org.eclipse.jetty.xml.XmlConfiguration $ 1.run(XmlConfiguration.java:1572)at org.eclipse.jetty.xml.XmlConfiguration $ 1.run(XmlConfiguration.java:1512)at java。位于sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)的sun.reflect.NativeMethodAccessorImpl.invoke(未知)的org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1511)上的security.AccessController.doPrivileged(本地方法)来自)org.eclipse.jetty.start.Main.invokeMain(Main.java:220)的java.lang.reflect.Method.invoke(未知来源)的sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) g.eclipse.jetty.start.Main.start(Main.java:490)at or.e.eclipse.jetty.start.Main.main(Main.java:77)2019-02-25 09:36:46.578:INFO: oejs.AbstractConnector:main:已启动ServerConnector @ 27808f31 {HTTP / 1.1,[http / 1.1]} {0.0.0.0:8080} 2019-02-25 09:36:46.594:INFO:oejs.Server:main:已启动@ 2970ms

java jetty jetty-9
1个回答
1
投票

注意:小心你的DOCTYPE,你声明的是从Jetty 7.x到Jetty 8.x,并且对于Jetty 9.x不正确

不要混合ResourceHandler和WebAppContext / ServletContextHandler。

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
   "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/mail</Set>
  <Set name="virtualHosts">
    <Array type="java.lang.String">
      <Item>apps.cairunet.ad.br</Item>     
    </Array>
  </Set> 
</Configure>

最基本的支持是不要在你的/ccmail中引用<Configure>

事实上,它作为${jetty.base}/webapps/ccmail/存在就足够了,它将部署/ccmail作为您的静态资源库。

但是,如果要将静态资源与虚拟主机相结合,则可以将WebAppContext与备用库或新的ResourceHandler一起使用。

替代碱基的例子:Serving static files from alternate path in embedded Jetty

ResourceHandler用法示例:https://www.eclipse.org/jetty/documentation/current/static-content-deployment.html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
   "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
  <Set name="contextPath">/ccmail</Set>
  <Set name="handler">
    <New class="org.eclipse.jetty.server.handler.ResourceHandler">
      <Set name="resourceBase">/fully/qualified/path/to/my/jetty.base/webapps/ccmail</Set>
      <Set name="directoriesListed">true</Set>
    </New>
  </Set>
  <Set name="virtualHosts">
    <Array type="java.lang.String">
      <Item>apps.cairunet.ad.br</Item>     
    </Array>
  </Set> 
</Configure>
© www.soinside.com 2019 - 2024. All rights reserved.