在运行期间在Eclipse中更新嵌入式Jetty Webapp [英] updating embedded jetty webapp in eclipse during run

查看:107
本文介绍了在运行期间在Eclipse中更新嵌入式Jetty Webapp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Maven生成的Web应用程序,该应用程序运行在嵌入式码头服务器中,所有服务器都塞进了一个胖子罐中. 这似乎可以正常工作,但是我们的UI开发人员不满意,因为在做UI时,他想更改自己的代码,而不必重新启动Webapp即可显示它.在我做所有罐子之前,它就像那样工作. 我们在pom中有一个资源部分,如下所示:

we have a maven generated webapp that runs in an embedded jetty server all stuffed into a fat jar. This seems to work fine but our UI developer is unhappy because when doing his UI stuff he wants to make changes to his code and not have to restart the webapp to have it show up. It was working like that before I did all the jar stuff. we have a resources section in the pom that looks like this:

    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
        <resource>
            <directory>src/main/webapp</directory>
            <targetPath>webapp</targetPath>
        </resource>
    </resources>

我们已经确定似乎正在发生的事情是eclipse正在将webapp复制到目标中的位置,然后从那里执行.我想他想要的是让eclipse使用src文件夹中的webapp源,并且仅在打包以进行部署时才复制webapp.

We've determined what seems to be happening is that eclipse is copying the webapp over to its location in target and then being executed from there. What he's wanting, I think, is to have eclipse use the webapp source in the src folder and only copy the webapp over when packaging for deployment.

将其设置为以预期方式工作的最佳方法是什么?

What would be the best way to set this up to work in the expected way?

推荐答案

您有拆分的资源方案.

传统上,WebApp有1个地方,即Webapp资源库(

Traditionally, a WebApp has 1 place to go, the webapp resource base (WebAppContext.setBaseResource() in Jetty). This is the where all static content, WEB-INF metadata (xml), WEB-INF/classes, and WEB-INF/lib/*.jar files are loaded from.

在您的方案中,您都是从target/mywebapp-1.0-SNAPSHOT加载所有内容(由maven-war-plugin的

In your scenario you are loading it all from your target/mywebapp-1.0-SNAPSHOT (actual path defined by maven-war-plugin's ${webappDirectory})

这是生产能力WebAppContext的典型和正常行为,因为它被配置为使用简单的战争路径基础资源.但是,您正在编辑src/main/webapp/目录中的文件(由maven-war-plugin的

This is typical and normal behavior for a production capacity WebAppContext, in that it is configured to use a simple War path or Base Resource. However you are editing files in your src/main/webapp/ directory (actual path defined by maven-war-plugin's ${warSourceDirectory}), which isn't part of the Base Resource directory.

您需要做的是忽略${webappDirectory}中的静态内容,并出于WebAppContext.setBaseResource()的目的使用${warSourceDirectory}中的静态内容,并从<外部使用类和jar(maven依赖项). c12>和${baseResource}/WEB-INF/lib

What you need to do is disregard the static content in ${webappDirectory} and use the static content in ${warSourceDirectory} for the purposes of the WebAppContext.setBaseResource(), and use the classes and jars (maven dependencies) from outside of the ${baseResource}/WEB-INF/classes and ${baseResource}/WEB-INF/lib

常规技术:

WebAppContext context = new WebAppContext();
context.setContextPath("/");

switch (getOperationalMode())
{
    case PROD:
        // Configure as WAR
        context.setWar(basePath.toString());
        break;
    case DEV:
        // Configuring from Development Base
        context.setBaseResource(new PathResource(basePath.resolve("src/main/webapp")));
        // Add webapp compiled classes & resources (copied into place from src/main/resources)
        Path classesPath = basePath.resolve("target/thewebapp/WEB-INF/classes");
        context.setExtraClasspath(classesPath.toAbsolutePath().toString());
        break;
    default:
        throw new FileNotFoundException("Unable to configure WebAppContext base resource undefined");
}

对于此行为的实时版本,请参见嵌入-jetty-live-war示例项目由Eclipse Jetty项目团队维护.

For a live version of this behavior, see the embedded-jetty-live-war example project maintained by the Eclipse Jetty project team.

这篇关于在运行期间在Eclipse中更新嵌入式Jetty Webapp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆