How to debug problems with GWT dev/hosted mode? - java

I'm trying to set up the GWT dev/hosted mode in a Maven-based Java webapp. I start my webapp via Maven Tomcat7 plugin (mvn tomcat7:run-war-only) and it is running fine. Also, startup of GWT via mvn gwt:run works and shows no errors.
However, if I access my webapp with the gwt.codesvr=127.0.0.1:9997 parameter, I just see a blank page in my browser. Interestingly, the page source contains the content of my JSP, but it is only defining some divs to be replaced by GWT.
How do I debug this situation? I haven't found any option for GWT dev mode to generate some kind of logging output. For example, it would be interesting to know if the GWT code server ever receives a call. At the moment, I'm missing any clue where to start looking why GWT dev mode is not working.

My original question was, how to debug Maven GWT plugin in case it is not doing what it is supposed to do. Here are a few hints which helped me during this process:
increase log level to ALL via config parameter
check in browser (e.g. via Firebug) that files of hosted mode like devmode.js and hosted.html are queried
insert Window.alert("..."); into the onModuleLoad() function to see if GWT code is executed at all
ensure that your app server is executing the exploded war (e.g., delete packaged WAR file before starting app server)
after startup of app server, don't call page without GWT codeserver parameter as this already generates some GWT files in the webapp exploded folder, which might conflict with those to be created by GWT hosted mode; take note which files are created and delete them manually
GWT dev mode seems to be not fully deterministic as I was able to get it running after forced reloading of the page in my browser
start from a working example, e.g. like the one I shared here: https://github.com/steinsag/gwt-maven-example

Related

How to correctly debug a GWT application with Jetty Runner in IntelliJ IDEA

I'm trying to migrate some legacy GWT applications from eclipse to IntelliJ. Oh man, what a nightmare. I've come very near to a dead end with my research. I'm at the point where there is simply no related page or documentation that I have not seen, not to mention the information on this topic is very, very sparse.
My setup is as follows:
IntelliJ IDE
GWT 2.9 plugin
Jetty Runner that is using Jetty v11.0.7
Here are my GWT and Jetty debug configuration settings:
When I navigate to the jetty server URL I always get "Error 404 Not Found" message.
Now, when I navigate to the "Debug" directory that is specified in the GWT configuration I do see that there is no RSS.html which is a problem but even the "blank.html" is not able to be navigated to. One potential issue is maybe I am somehow not compiling the debuggable version of the GWT application correctly?
My other guess is that I have to somehow point to an actual .war file. I do have an ant build script that works just fine and generates a .war that works correctly in production. Below is a screenshot of the generated war file as well as the directory used to build the war archive.
In summation, how do you correctly debug a GWT application in IntelliJ using the GWT configuration with a Jetty Runner server?
I can promptly provide any additional info that I may have left out.
EDIT
I would like to add that this How to get GWT Super Dev Mode to work with IntelliJ question is very similar to what I am asking here and it was never edited with the correct answer, also since this was posted super dev mode was added. It would be great to get a clear solution documented for myself and others. To reiterate the answer needs to achieve these three things,
Use a Jetty Runner configuration (to enable use of different Jetty versions as there can be a cascade of conflicts depending on your codebase)
Use a GWT configuration to run a code server with the Jetty Runner instance so debugging is possible.
Use IntelliJ IDEA

How to enable Hot deployment in JBoss using Redhat server connector extension in VSCode

I have made a small maven based web application in VSCode and trying to deploy it on JBoss using the Redhat Server Connector Extension.
But the hot deployment of the class files does not work in simple running JBoss server.
But Hot deployment does work in debug mode as 'Hot Code Replace' by setting the property 'java.debug.settings.hotCodeReplace' to 'auto'.
My inputs are from below links:
https://devblogs.microsoft.com/visualstudio/hot-code-replacement-for-java-comes-to-visual-studio-code/
and other SO links like:
How do I get Java "hot code replacement" working in JBoss?
Hot deploy on JBoss - how do I make JBoss "see" the change?
But it couldn't help.
Can you suggest something more about how it is simply possible in running JBoss?
(PS: Auto Build feature in VSCode is already enabled.
And It works fine in eclipse).
Hot deployment of web applications in VSCode's integrated RedHat Server connector can occur in following ways:
Exploded war folder: A folder is extracted from the original war and deployed to JBoss using the Exploded option. Here, the static changes like change in jsps and HTML are automatically reflected in the running application.
Hot code Replacement: Hot code replacement (HCR) is a fast debugging technique in which the Java debugger transmits new class files over the debugging channel to another JVM.
HCR only works when the class signature does not change; you cannot remove or add fields to existing classes when using HCR. However, HCR can be used to change the body of a method.
(source: https://devblogs.microsoft.com/visualstudio/hot-code-replacement-for-java-comes-to-visual-studio-code/)
Maven Install/build: It is actually not a preferred technique which someone will want but it is useful also. In this technique, you run maven: install which builds the project again and install it onto the server again.
Currently, VSCode for java and the server connector extension are new as compared to already available IDEs like Eclipse. So, we might expect more powerful functionality in coming future.

Deploy Struts2 WebApp Within An Eclipse RCP Application Via Jetty

Now here's a mess for you...
I am currently working on an Eclipse RCP application plugin. The goal of this plugin is to serve up a webapp for users to interact with within an Eclipse ViewPart (SWT browser control).
I would like for this webapp to be powered by Struts2 and I already have Jetty at my disposal for serving things up.
Is there any way at all I can deploy a Struts2 WebApp in this way? If more info is needed please ask!
EDIT #1:
Some more detail. The only way I know how to deploy a struts2 application currently is via a war file (hosting on tomcat, that is). This is not something I can do in this case. I need to somehow deploy struts2 internally in an embedded way using the Jetty server provided with the Eclipse RCP framework.
RESULT:
As it turns out you can deploy a WAR file (struts2 app in this case) with embedded Jetty. I found Joakim Erdfelt doing it here: Embedding Jetty as a Servlet Container
Struts2 web application can run in the servlet container like Jetty. Jetty also have an embedded option. Eclipse RCP uses Eclipse platform for extension and customization with plugins. There's an article of using Eclipse RCP with embedded Jetty server:
First, let’s add the jetty plugin to our dependencies. Open the tab
Dependencies in your plugin configuration. Then add these six
plugins to the Required Plug-ins:
javax.servlet
org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.regstry
org.eclipse.equinox.http.servlet
org.mortbay.jetty.server
org.mortbay.jetty.util
In the list of plugins included at the launch of application you need
to change the Auto-Start value for three plugins to true (if you are
lazy, you can turn the default behavior to auto start but this is
another concern):
org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.regstry
org.eclipse.equinox.http.servlet
Now if you run the application you can check if your server is
correctly running by accessing http://localhost. This should work
flawlessly except maybe if you are not allowed to run server in port
80 or there is already a server running in port 80.
You can change the port by adding an argument to the VM arguments in
Run Configurations. Add this value:
-Dorg.eclipse.equinox.http.jetty.http.port=8888. Change 8888 to
whatever port you want the server to be running.
Now if you are running the application, you can access it from the
port you mentioned before.
The next task is to define one (or several) servlet(s) that will serve
any request the server gets. To do this, you need to open the
Extensions tab from your plugin configuration and add a new
extension named org.eclipse.equinox.http.registry.servlets. After
that add new servlet. You need to mention the class name of the
servlet, and an alias for that. One note here is you need to add slash
in front of the alias. For example, if you want to make the servlet
accessible from http://localhost:8888/webserviceInterface, then the
alias value is /webserviceInterface. Of course, you need to
implement a servlet which will do the work you want.

Is there any guide showing how to build effectively an application with appengine and maven in eclipse?

I'm trying to develop an application using Google App-Engine and Maven using Eclipse. I am facing a problem where by whenever you change a CSS or JSP file, a restart of the application is required. This makes working quite difficult, since a reload takes a lot of time.
For example when you develop on tomcat no need for restart is required when such a change is made, only Java or xml file require restart of the server.
Is there a solution that mimics the tomcat behavior on GAE SDK when developing on localhost?
If you've built using the standard app engine maven archetype, when you run mvn appengine:devserver from you -ear directory, the exploded war working directory is located here:
<yourapp>/<yourapp>-ear/target/<yourapp>-ear-1.0-SNAPSHOT/<yourapp>-war-1.0-SNAPSHOT.war
If you change any JSPs in this directory, they will get reloaded without needing to restart the devserver.
Thus, you can set up a simple script or command that copies all your JSPs and static files from /-war/src/main/webapp to that deploy directory whenever you want your files to be refreshed. I saw on some threads where people set up their IDE (in this case IntelliJ) to automatically do that copy whenever the IDE loses focuses, which makes it trivial to get pages reloaded.
Building application with appengine in eclipse using maven is not very effective and time consuming because on every change on jsp/css/js with a traditional approach there is a need to restart appengine or mvn appengine:devserver.
#adevine make me thought about a solution, and I found this link: http://andrei.gmxhome.de/filesync/index.html wich installs a plugin in eclipse, then I activate the project to sync files from myapp/src/main/webapp to a target folder generated by maven myapp/target/myapp-snapshot-0.0.1.
It's working!!!
Whenever a change is done in webapp the files are transfered automtically(no need to run anything else, just save the file) to the target folder and are reloaded successfully.
Hope this could help people because its frustrating working with appengine(restarts takes a lot).

Debug GWT app locally/remotely while running on Tomcat

All of the tutorials/links/articles I have found for debugging GWT involve:
Using the Google-Eclipse plugin; and
Running GWT in Development Mode from inside Eclipse (with Eclipse as the web container)
I would like to know how to debug a GWT app while it runs from a non-Eclipse web container; specifically a full-blown Tomcat instance that is either running on the same machine (localhost:8080) or on a remote machine somewhere else.
Ideally, I'd be able to access my app normally, via browser, but as I interact with the app (clicking buttons, etc.), Eclipse would be running in Debug mode, and would hit breakpoints that I set ahead of time (before the deploy).
To my surprise, there isn't much out there on this that I could find, and certainly nothing definitive. So I was wondering if any battle-weary GWT veterans could shed some light on how I could do this.
If at all possible, I'd prefer not to install the Google-Eclipse plugin, unless that is the only option for achieving this. Thanks in advance!
I am not sure if you missed this documentation. I used to do remote debugging in my dev mode where my server is running in the VM. I can suggest you two solutions.
If you are using a version prior to GWT 2.5 you have to give the noserver argument in launch configuration providing the url for the host page in the server (Tomcat etc). I have extracted the steps from above documentation.
Configure your server however you need to; note the URL which contains the host page for your GWT application.
Arrange all your static content files (such as the host HTML page, images, CSS, etc.) on the server however you like.
Edit your development mode execution script (such as your Eclipse run configuration or the ant development build target generated by the GWT webAppCreator) and add or update the following options:
• Add the -noserver command line argument.
• Change the URL at the end of the argument list to match the URL you recorded in step #1.
Compile your application once using the ant build target. Ideally, you can use GWT's -war option to generate output files directly into your external server's static content folder. Otherwise, you'll need to copy the the GWT output folder from war/ to your external server's static content.
If you are using 2.5 or above you can use super dev mode. In super dev mode you can debug using the browser so no need of eclipse plugin. I have tried this and worked fine. However I was unable to load the java sources using source maps. Here is the documentation for superdevmode configuration.
It's really easy, just follow these steps:
Get google plugin for eclipse
The in eclipse, right click on your project and choose Debug as -> Web Application (running on external server)
Enter URL of your web app on tomcat (like
http://localhost:8080/YourApp/YourApp.html
and eclipse will give you new one - it will add stuff like ?gwt.codesvr=127.0.0.1:9997
And that's it. Just set up your breakpoints and debug!
Also take a look on this

Categories