Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot replace of static resources (html, png, etc.) #285

Open
kalatchev opened this issue Apr 16, 2020 · 5 comments
Open

Hot replace of static resources (html, png, etc.) #285

kalatchev opened this issue Apr 16, 2020 · 5 comments

Comments

@kalatchev
Copy link

  • VSCode Version: 1.44.0
  • OS Version: Windows 10
  • Tomcat Extension Version: 0.11.1

Extension works just fine. Excellent job! However, I have a question/issue with hot reload. When I change some java class, hot relaod does work. But when I change some static files, such as html, I am not able to tell the Tomcat to reload it. How can I do that?

@obarbier
Copy link

any update in this. I am facing the same issue. I try to play around server.xml but I am not having any luck

@wecharyu
Copy link

Same issue.

@andxu andxu self-assigned this Jun 29, 2020
@andxu andxu added the backlog label Jun 29, 2020
@HKChen
Copy link

HKChen commented Aug 14, 2020

@kalatchev you can use extension of fsdeploy, the setting follow below in user setting on vscode

"fsdeploy.nodes": [

    {
        "source": "${your java source WEB-INF path}",
        "target": "${your java target WEB-INF path}",
        "include": "**/*.*",
        "exclude": "**/min/*.*"
    }
]

Then you can run tomcat project and modify static resources. After edited, you can refresh web page and you will found it's changed.

@vutahoanghiep
Copy link

I confirm that fsdeploy is a good solution. Just do it before using fsdeploy: determine Tomcat workspace in the setting of plugin then choose the target from this path

@stellarbeam
Copy link

stellarbeam commented Mar 1, 2022

I found a solution inspired by IntelliJ's Smart Tomcat plugin's approach, which does not need repeated copying of files
For this, we need to change the configuration of Tomcat a little bit.

  1. First, run mvn compile followed by mvn war:exploded ( no need to generate WAR file, we directly use the webapp folder instead). This can be setup as a VS Code task like following:
{
    "version": "2.0.0",
    "tasks": [
        // ... other tasks ...
        {
            "label": "compile",
            "type": "shell",
            "command": "mvn compile"
        },
        {
            "label": "generate webapp",
            "type": "shell",
            "command": "mvn war:exploded"
        },
        {
            "label": "Build Webapp",
            "dependsOrder": "sequence",
            "dependsOn": [
                "compile", "generate webapp"
            ]
        }
    ]
}

This will create lib and classes directories in newly created target/<project-name>/WEB-INF directory, among others.

  1. Right click on the Tomcat server in left pane, and click on Open Server Configuration. This will open server.xml file

  2. Then, in <Host> element, add the <Context> element as follows:

      <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b"/>

        <!-- ADD THIS -->
        <Context docBase="/<absolute-path-to-project>/src/main/webapp" path="/<project-name>">
          <Resources>
            <PreResources base="/<absolute-path-to-project>/target/<project-name>/WEB-INF/classes" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes"/>
            <PostResources base="/<absolute-path-to-project>/target/<project-name>/WEB-INF/lib" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib"/>
          </Resources>
        </Context>
        <!-- ADD THIS -->

      </Host>

Note that the absolute paths to lib and classes directories can be obtained by Right click > Copy path in left pane.
Make sure you replace the <project-name>, and <absolute-path-to-project> at 3 places.

Now the Tomcat Setup in ready. Above steps are needed only one time for a project.

Right click on the target/<project-name> folder and choose Debug on Tomcat Server. All files under the src/main/webapp directory will be directly used by Tomcat so changes will reflect with simple browser refresh, and changes to Java files will be reflected with Hot Reload as usual.

If you use the hot reloading feature, I suggest running mvn compile before each time you start the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants