GWT开发模式不会在css文件更改时重新加载

7
我使用Gradle作为构建管理器设置了一个GWT项目,一切正常。我可以将我的项目部署到eclipse中的本地tomcat中,并且应用程序按照预期运行。但是,如果我启动DevMode并更改CSS资源中的某些内容(这些资源被绑定为带有@Source注释的CssResource类),则GWT DevMode不会捕获它,CSS更改不会得到考虑。我错过了什么吗?我希望DevMode能够在开发过程中检测.css文件中的更改,而无需再次运行gwt编译。
以下是我如何使用CSS资源的示例:
public interface XOFooterPanelResource extends FooterPanelResource, ClientBundle {
    @Override
    @Source("XOFooterPanel.css")
    XOFooterPanelStyle style();

    @Override
    @ImageOptions(repeatStyle = RepeatStyle.Horizontal)
    ImageResource footerPanelBackground();

    @Override
    @ImageOptions(repeatStyle = RepeatStyle.Horizontal)
    ImageResource footerPanelBackgroundEndUser();

    @Override
    @Source("footerDelimiter.jpg")
    ImageResource footerDelimiter();
}

public interface XOFooterPanelStyle extends FooterPanelStyle, CssResource {

}

您可以看到我有一个名为XOFooterPanelStyle的接口,它继承了CssResource。在XOFooterPanelResource中使用@Source注释并加上我的CSS文件名称来使用它(XOFooterPanelResource也是通过继承ClientBundle来使用)。

这里是负责启动DevMode的gradle构建文件的一部分:

javaexec {
        main = 'com.google.gwt.dev.DevMode'

        jvmArgs = ['-Xmx2048M', '-XX:MaxPermSize=1024M']

        classpath {
            [
                sourceSets.main.java.srcDirs,
                // Java source
                sourceSets.main.output.resourcesDir,
                // Generated resources
                sourceSets.main.output.classesDir,
                // Generated classes
                sourceSets.main.compileClasspath       // Deps
            ]
        }

        args = [
                '-startupUrl', 
                'myapp/index.html', 
                '-noserver',
                '-war',
                'build/devmode',
                '-gen',
                'gen'
            ]
        ext.gwtModules.each {
            args += it
        }
    }

如前所述,我正在使用 Eclipse 中的 Tomcat 运行应用程序,因此设置了 -noserver 选项。

1个回答

0

除非您直接更改tomcat引用的css文件,否则您将无法在开发模式下看到更改。我相信当您通过eclipse部署时,您的代码不会直接从eclipse项目工作区引用,而是将副本移动到tomcat webapps文件夹中。

我不确定在这种情况下的标准解决方法是什么。我觉得应该有一种选项可以从eclipse刷新tomcat实例的静态资源,但我还没有研究过。

以下是我需要时解决此问题的两种方法:

1)您可以将CSS代码放入ui.xml文件中,这样就可以在devMode中获取到。
如何向您的ui.xml添加CSS的教程

2)您还可以直接修改webapps文件夹中的css文件,然后将您所做的任何更改迁移到工作区版本。


作为一种解决方法,使用maven-resources-plugin copy-resources,<directory>src/main/webapp</directory><outputDirectory>${project.build.directory}/gwt-webapp</outputDirectory>。 https://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html - Daniel Hári
我在webapps文件夹中对CSS文件所做的更改似乎没有被采用,在页面刷新时gwt会显示“跳过编译,因为没有更改输入文件”? - xji

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接