redhat-developer / vscode-server-connector

📦 Connects Visual Studio Code to your server adapters and run, deploy apps !!
Eclipse Public License 2.0
56 stars 26 forks source link

Static files are not updated (xhtml, css, etc.) #573

Closed zicheee closed 6 months ago

zicheee commented 1 year ago

I am currently switching from Eclipse to VS Code and for now I am testing a plain war maven project.

I created a class TestView

import java.io.Serializable;

import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named
@ViewScoped
public class TestView implements Serializable {

    public String getTest() {
        return "Lorem Ipsum ";
    }

}

and also an index.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">

<body>
    <h1>Hello World</h1>
    <h:outputText value="#{testView.test}" />
</body>

</html>

I downloaded Wildfly 24 and configured the server according to the video tutorial (https://www.youtube.com/watch?v=sP2Hlw-C_7I). When I change the return value of the java class, everything is working like expected and the view is updated moments later. But when I change the index.xhtml file and write e.g.

<h1>Hello World - Test</h1>

nothing is done. I need to run maven package to force an update.

Is this a bug if this extension or is some configuration wrong?

robstryker commented 1 year ago

Hi, I'd like to help but I need a bit more information.

Can you tell me what your project / folder structure looks like, and which folder you've chosen to mark as the deployable folder?

This sounds very similar to an issue I was recently working on solving, specifically that while jdt.ls will automatically compile and update your class files in your target folder, nothing is actually rebuilding the exploded-war output folder other than a full maven build.

I came up with a packaging descriptor that one could add in their project to assemble file changes from multiple folders, but I haven't fully documented it yet.

zicheee commented 1 year ago

Hi robstryker,

I created a new war project using the maven command: new-project

And then I selected the web-application: create-web-project

After everything was created I added a beans.xml file, a faces-config (2.3) and I addded some information to the web.xml. My whole project looks like this: folder

I uploaded the complete code to this repository: https://github.com/zicheee/vscode-war-project

The server is started in debug mode and is using the following configuration:

{
  "args.override.boolean": "true",
  "args.program.override.string": "-mp \"c:\\bin\\jboss\\wildfly-24.0.1.Final\\modules\" org.jboss.as.standalone -b localhost --server-config=standalone.xml",
  "args.vm.override.string": "\"-Dprogram.name=rsp:WildFly 24+\" -server -Xms64m -Xmx512m -Dorg.jboss.resolver.warning=true -Djava.net.preferIPv4Stack=false -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true \"-Dorg.jboss.boot.log.file=c:\\bin\\jboss\\wildfly-24.0.1.Final\\standalone\\log\\boot.log\" \"-Dlogging.configuration=file:c:\\bin\\jboss\\wildfly-24.0.1.Final\\standalone\\configuration\\logging.properties\" \"-Djboss.home.dir=c:\\bin\\jboss\\wildfly-24.0.1.Final\" -Dorg.jboss.logmanager.nocolor=true -Djboss.bind.address.management=localhost --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED --add-modules=java.se -Djboss.http.port=\"8080\"",
  "id": "WildFly 24+",
  "id-set": "true",
  "jboss.server.host": "localhost",
  "jboss.server.port": "8080",
  "org.jboss.tools.rsp.server.typeId": "org.jboss.ide.eclipse.as.wildfly.240",
  "server.autopublish.enabled": "true",
  "server.autopublish.inactivity.limit": "1000",
  "server.home.dir": "c:\\bin\\jboss\\wildfly-24.0.1.Final",
  "server.timeout.shutdown": "120000",
  "server.timeout.startup": "120000",
  "vm.install.path": "c:\\bin\\java\\jdk-11.0.17+8",
  "wildfly.publish.restart.pattern": "\\.class$|\\.jar$",
  "wildfly.server.config.file": "standalone.xml",
  "wildfly.server.deploy.directory": "",
  "deployables": {
    "c:\\Temp\\demo\\target\\demo": {
      "label": "c:\\Temp\\demo\\target\\demo",
      "path": "c:\\Temp\\demo\\target\\demo",
      "options": {
        "option": {
          "deployment.output.name": "demo.war"
        }
      }
    }
  }
}

When I change anything in the index.xhtml nothing is updated. I need to manually run maven package which causes the deployment to be replaced completly. So I have no idea what to configure differently.

KaranLala commented 7 months ago

I have this issue too. Java classes can be hot deployed using vscode-java-debug but changes to JSP files, for example, are ignored. The project is built purely on Maven. Is there a way republish changes, other than rebuilding with Maven?

robstryker commented 6 months ago

Hey all: So, I know this requires a bit of explaining. I'm gonna do my best. I can't say the solution is elegant, but there is a solution (mostly).

When you add a deployment to a server, you can either add a single file (xml, war, jar, etc) or you can set a folder to add. Any changes to that file or folder will be picked up, and, additionally, in the case of a folder, any change to any recursive children will also be recognized.

Now, upon first glance this sounds fine. Upon investigation, it doesn't. For exploded applications, it basically means you need to deploy the build output directory. And the problem there is that when you change an html file, or a jsp file, or an xml file, in a source folder, it does not make it to the output folder without a rebuild / re-run of maven or similar. In fact, even in the case of class files, some project structures (like when using jdt.ls) will have an automatic build / compilation folder that is different than the project's output folder (think build/ instead of /target/MyApp/MyApp.war/ or similar) and only upon a run of maven does this file get assembled in your build output folder.

The solution is explained (vaguely) here: https://github.com/redhat-developer/vscode-rsp-ui/#provisional-project-structure-details

In short, we tried to copy the basics of the wtp assembly file and add this concept. To accomplish this, you would instead add a .rsp/rsp.assembly.json file to the root of your project tree. This file would list a set of mappings, of source folders to where the file belongs in the output exploded archive. This will allow the rsp server to recognize changes in a source folder (or, in the case of .class files, an auto-compilation of a changed java file) to where it belongs in the output archive (web-inf/classes/org/etc)

If you go look at the example, you can see that the second mapping is the actual output of the maven build, while mappings 1, 3, and 4 can bring in or recognize changes in files or folders that need to be updated for incremental changes.

Now remember this is an example structure, and you can add whatever mappings you want here. Depending on your project structure and where jdt.ls puts incrementally compiled classes, you can add that mapping in. The 3rd and 4th mapping in this example attempt to recognize changes in the source folders for resources or webapp files, ie, xml files and other configuration files or static files like html, jsp, images, etc etc.

There is currently no support for nested jars / nested projects / EAR projects / etc. But this should cover the basics.

I hope this explanation helps a bit and sorry for the delay in getting back to you all.

robstryker commented 6 months ago

As of now, this is all the information I have to share. If you have specific bugs or feature requests with the above feature, please open a new issue.