Search code examples
javascriptjavagwtinterop

Where to put custom javascript files in a GWT JSinterop java program?


I'm new to GWT and JSinterop. I want to call javascript functions that I write from the GWT app. The tutorials are confusing and leave out the basics. My GWT app created a large tree of files. Where do I put the javascript files that I create?

Here? src>com.gwtext>client

Here? src>com.gwtext>public>js

Here? src>com.gwtext

Here? com.companyname.projectname

Here? war>projectname>js

Here? war>js

Here? war>js>com>gwtext>client

Here? war>js>com>>gwtext>public>js

Here? war>js>ext-2.02 or one of its many subdirectories?

Here? war>WEB-INF

The tutorials assume you know the basics but nowhere can you find the basics. Where can I find a GWT tutorial that starts from the beginning, including the basics?


Solution

  • The web application sources, such as Javascript files and libraries, should be placed in src/main/webapp if you use Maven. In your example, that would be inside the war folder. There, you can create a deeper folder structure to organize a larger number of files. That's up to you.

    Your GWT Application/Library sources should be placed in the src folder in your example. That would be src/main/java if you would use Maven. There, you should place the JsInterop classes - the classes that include JsInterop annotations.

    With that in mind, for a complete understanding of a GWT project structure, http://www.gwtproject.org/doc/latest/DevGuideOrganizingProjects.html is a good reference.

    After understanding the GWT project structure, http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJsInterop.html helps understanding how JsInterop works. In the end of that page there is a link to the full example: https://github.com/zak905/jsinterop-leaflet. That is useful to understand the project structure, as far as JsInterop is concerned.