无法将外部应用程序部署到jetty 9.0.6.v20130930

时间:2013-10-30 14:50:20

标签: jetty

当我通过在jetty / webapps中复制它来部署我的应用程序时,它就可以部署了。但我想从外部目录部署它。为此,我创建了myconf.xml:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<Configure id="myapp" class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="server">
        <Ref refid="Server" />
    </Set>
    <Set name="contextPath">/myapp</Set>
    <Set name="war">
        <SystemProperty name="myapp.war" /><!-- points to the external war -->
    </Set>
</Configure>

然后jetty运行:

java -XX:-UseSplitVerifier -jar start.jar myconf.xml。

在控制台中,我看到正在部署应用程序,它访问数据库等,但当我尝试访问它时,我得到了404.任何帮助都非常感谢:)

最好的问候,尤金。

1 个答案:

答案 0 :(得分:0)

这不是你使用Jetty的方式。

选项1:标准自动部署

  1. 由于您没有使用部署自定义任何内容,因此只需完全删除myconf.xml
  2. myapp.war复制到${jetty.home}/webapps/目录。
  3. 启动Jetty。 $ java -jar start.jar
  4. 这称为Automatic Web Application Deployment

    选项2:标准上下文部署

    现在,如果你想自定义部署,(例如你想要调整它监听的上下文路径,或者你想要禁用extractWar进程,或者你有自定义init参数,或者你甚至想要更改默认servlet的行为等...),然后执行以下操作...

    1. 将现有的myconf.xml复制到${jetty.home}/webapps/myapp.xml(请注意名称更改)
    2. 将您的myapp.war复制到${jetty.home}/webapps/myapp.war(请注意,此文件的基本名称应与您的XML相同)
    3. 编辑${jetty.home}/webapps/myapp.xml以更改部署行为(例如:<Set name="contextPath">/app/1</Set>
    4. 启动Jetty。 $ java -jar start.jar
    5. 这称为Configuring Specific WebApp Deployment

      选项3:自定义上下文部署

      如果您想将war文件保留在${jetty.home}/webapps/以外的其他位置,您仍需要执行以下操作:

      1. 将现有的myconf.xml复制到${jetty.home}/webapps/myconf.xml
      2. myapp.war留在您想要的位置。例如/opt/webapps/myapp.war
      3. 修改您的${jetty.home}/webapps/myconf.xml以设置contextPathwar条目。
      4. 启动Jetty。 $ java -jar start.jar
      5. <?xml version="1.0"?>
        <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
            "http://www.eclipse.org/jetty/configure_9_0.dtd">
        
        <Configure id="myapp" class="org.eclipse.jetty.webapp.WebAppContext">
            <Set name="server">
                <Ref refid="Server" />
            </Set>
            <Set name="contextPath">/myapp</Set>
            <Set name="war">
                <SystemProperty name="/opt/webapps/myapp.war" />
            </Set>
        </Configure>
        

        选项4:Jetty Base自动部署(可在Jetty 9.1 +中使用)

        还有另一种技术,从Jetty 9.1开始,使用拆分${jetty.home}${jetty.base}概念+上面的自动部署。

        假设您已将jetty-distribution-9.1.x解压缩到/opt/jetty/,并且您在/opt/myapps/中拥有了您的webapp +配置。您可以执行以下命令。

        [user]$ cd /opt/myapps
        
        [myapps]$ java -jar /opt/jetty/start.jar --add-to-start=server,deploy,websocket,ext,resources
        server          initialised in ${jetty.base}/start.ini (appended)
        server          enabled in     ${jetty.base}/start.ini
        deploy          initialised in ${jetty.base}/start.ini (appended)
        deploy          enabled in     ${jetty.base}/start.ini
        MKDIR: ${jetty.base}/webapps
        server          enabled in     ${jetty.base}/start.ini
        websocket       initialised in ${jetty.base}/start.ini (appended)
        websocket       enabled in     ${jetty.base}/start.ini
        server          enabled in     ${jetty.base}/start.ini
        ext             initialised in ${jetty.base}/start.ini (appended)
        ext             enabled in     ${jetty.base}/start.ini
        MKDIR: ${jetty.base}/lib
        MKDIR: ${jetty.base}/lib/ext
        resources       initialised in ${jetty.base}/start.ini (appended)
        resources       enabled in     ${jetty.base}/start.ini
        MKDIR: ${jetty.base}/resources
        
        [myapps]$ ls -l
        total 16
        drwxrwxr-x 3 user group 4096 Oct 31 08:32 lib/
        drwxrwxr-x 2 user group 4096 Oct 31 08:32 resources/
        -rw-rw-r-- 1 user group  369 Oct 31 08:30 start.ini
        drwxrwxr-x 2 user group 4096 Oct 31 08:30 webapps/
        
        [myapps]$ cat start.ini
        --module=server
        threads.min=10
        threads.max=200
        threads.timeout=60000
        jetty.dump.start=false
        jetty.dump.stop=false
        
        --module=deploy
        --module=websocket
        --module=ext
        --module=resources
        
        [myapps]$ java -jar /opt/jetty/start.jar --list-config | grep -E "jetty.(base|home)="
         jetty.home=/opt/jetty
         jetty.base=/opt/myapps
        
        [myapps]$ cp /home/user/project/myapp/target/myapp-1.0.war /opt/myapps/webapps/myapp.war
        
        [myapps]$ java -jar /opt/jetty/start.jar
        2013-10-31 08:35:58.919:INFO:oejs.Server:main: jetty-9.1.0.RC0
        2013-10-31 08:35:58.939:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/opt/myapps/webapps/] at interval 1
        2013-10-31 08:35:59.109:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /myapp, did not find org.apache.jasper.servlet.JspServlet
        2013-10-31 08:35:59.189:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@223ff173{/myapp,file:/tmp/jetty-myapp.war-_myapp-any-/webapp/,AVAILABLE}{/myapp.war}
        

        您会注意到您有2个可以使用的位置。

        • ${jetty.home} - 您的码头分布位于
        • ${jetty.base} - 应用程序的特定配置和战争所在的位置

        这是一个非常强大的选择,我只触及其功能的表面。

相关问题