Home > Back-end >  How to sync java project changes to Tomcat's web app
How to sync java project changes to Tomcat's web app

Time:11-22

So I'm currently using VS Code for my simple java webapp, but I find it a bit tedious as I would have to deploy a .war file every time I make changes to the project itself.

The full procedure is this:

  • Maven => Plugins => war:war
  • Publish Server (full)
  • Restart in Run Mode
  • Open the servlet

This process takes about 3-5 seconds, which isn't the best since every developers constantly test / debug / updates their code.

The current extension that I use in VS Code to deploy the Tomcat server is the Community Server Connector.

I wonder if there is a way to fully sync the web app with the changes made to the project itself

CodePudding user response:

You can use the enter image description here

Here is a simple maven project as an example.

enter image description here

compile project in MAVEN panel

enter image description here

After downloading the extension, add the following configuration in settings.json.

    "deploy": {
        "packages": [
            {
                "name": "frontend",
                "description": "All files in webapp",
                "files": [
                    "src/main/webapp/*",
                    "src/main/webapp/*/*",
                    "src/main/webapp/*.*",
                    "src/main/webapp/*/*.*",
                    "src/main/webapp/*/*/*.*",
                    "src/main/webapp/*/*/*/*.*",
                    "src/main/webapp/*/*/*/*/*.*",
                    "src/main/webapp/*/*/*/*/*",
                    "src/main/webapp/*/*/*/*/*/*.*",
                ],
                "exclude": [
                    "src/main/webapp/test/*"
                ],
                "deployOnSave": true,
                "useTargetList": true,
                "button": {
                    "text": "Deploy",
                    "tooltip": "Click here to deploy frontend to hotsite",
                    "targets": [ "HOTSITE" ]
                },
            }
        ],
        "targets": [
            {
                "type": "local",
                "name": "HOTSITE",
                "description": "A local folder",
                "dir": "target/DETE/",
                "mappings": [
                    {
                        "source": "src/main/webapp",
                        "isRegEx": false,
                        "target": "/"
                    }
                ]
            }
        ]
    }

After the addition is complete, click the Deploy button that appears in the status bar below.

enter image description here

Right-click on the tomcat server and select Add Deployment

enter image description here

Next select Exploded

enter image description here

Select the DETE folder generated by just clicking Deploy in the explorer

enter image description here

Type http://localhost:8080/DETE in the browser address bar and press Enter

enter image description here

Or right-click on tomcat and select Server Actions... --> Show in Browser... --> http://localhost:8080/DETE

Modify .jsp to add a line of content

enter image description here

Refreshing the page shows the changed content.

enter image description here

  • Related