Debug GWT app locally/remotely while running on Tomcat - java

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

Related

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.

How to debug problems with GWT dev/hosted mode?

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

Can Eclipse automatically refresh Tomcat app?

I use Eclipse Indigo (EE) to build applications in Java framework Vaadin,
using Tomcat 7.0 server. After changes in code I wont see result in a browser,
so I need to click option "Clean Tomcat Work Directory.." and wait until
Tomcat stop and start a server.
Otherwise, when I refresh app page, I don't see any changes.
Even when I restart server (and when eclipse automatically restart it when I save changes), without cleaning tomcat directory.
Option "Automatically publish when resources change" is enabled.
Is any faster way to do that? or can I automate that process?
Additionally to the answer of Kowser, it is possible do hot code changes when running tomcat in debug mode.
Otherwise you could investigate in JRebel
In your "Modules" tab of your Tomcat, you hace to clic on 'Edit' and uncheck the 'Auto reloading enables' option.
With that, several changes won't need a restart (as long as you start your server in debug mode).
If you setup your project to use ant for building and deploying, you can simply add Ant builder to your project Builders to run your ant build and deploy targets every time after you have saved a file. Then provided that tomcat is configured to support auto-deploy, this should achieve what you want, with two caveats:
If your project takes more than a few seconds to build, building after every save is not practical.
You may run out of memory for the tomcat instance if the same app is deployed to it repeatedly for a number of times. This can happen if tomcat is somehow unable to recover all the memory from undeployed resources.
It might be possible. But your setup is a bit different from what I use. I am just using tomcat+eclipse to do Servlet development using Velocity and Torque.
The following works for me where changes are visible in the browser as soon as I save in eclipse.
I assume that you have a project directory such as
apache-tomcat-7.0.11/webapps/$YOU_PROJECT/WEB-INF/classes/
Create a symbolic link with ln -s from your eclipse project directory and to the classes directory in WEB-INF.
Then configure eclipse to write all .class files to this directory. (Done by right clicking on the project in Eclipse and choosing Properties and then Java build path.
In your $tomcat/conf/context.xml config file first tag should be:
<Context allowLinking="true" reloadable="true">
Also add the following as a child to if it is not already there.
<WatchedResource>WEB-INF/web.xml</WatchedResource>
That is what I have done, but I am not sure it works with your EE tools.
ps: This solution assumes that you are using linux/unix. I don't know if it works with windows. The major problem is that eclipse can't write class files outside the project directory (Which is why that symlink is required).
btw: Tomcat may(Depending on class loader, used .jar files and other complicated details) leak a lot of memory when automatic reload is enabled so you may want to increase the allowed memory(Mostly permgen) to prevent out of memmory exceptions from tomcat.
I know this has been asked and answered very long ago. But use this info if it is helpful to anyone of you. I use Eclipse Kepler and configured Tomcat 7 server inside eclipse. I don't have to do any other configuration but to just uncheck Update context paths check box. That is all. Leave other setting as default.
In this way, changes to the resources files (xhtml pages, css files etc.) as well as the java source code files show up in the browser. Only for class files the web application would be redeployed (no server restart auto as well as manual required).
Location of Update context paths: Double click on the tomcat server under Server tab. Under Publishing tab you would find this Update context paths check box.
Absolutely no other change needs to be done for the auto publishing. This works both in normal and debug mode of tomcat.
Screen shot from my eclipse below:
No, there is no other way.
You will notice immediate changes only while updating a JSP/HTML/etc.... Classes will not be loaded/refreshed automatically. It will be contradictory to change a loaded/instantiated class when server is live, isn't it? At least it should not be possible.
It's better to perform Unit Test while developing something. It can help you to reduce the amount of annoying server restarts.

Sharing Local GWT Project with the rest of the world?

As you all probably know, when you create a GWT project (I use Eclipse..not that it matters), and you run it as a web application, you get the application URL, for instance:
http://127.0.0.1:8888/StockWatcher.html?gwt.codesvr=127.0.0.1:9997
My question is, I would like to let my friend, which is on a different computer, this URL so he can also check the application, so I changed the 127.0.0.1's to my own IP, but it doesnt do the trick, what am I missing here?
Thanks,
If you want to share your app with rest of the world, you need to deploy it on some sort of web server. You can pick many of them, f.e. Apache Tomcat, Jetty, JBoss, GlassFish ... Basically, your application needs some sort of container to run in.
I will now briefly describe deploying GWT app to Tomcat:
You must have globaly accessible IP (and also domain name)
Install Apache Tomcat, see the documentation
Eclipse with Google plugin created for you folder structure containg /war folder
Copy /war folder to to Tomcat webapps (by default /Apache Tomcat X/webapps. You might want to rename your war folder, say to "StockWatcher"
Add necessary libraries to /lib folder (but Tomcat will complain about missing classes, not difficult to find out what's wrong here)
Restart tomcat and type URL like: http://your_url:your_port/YourApp/YourApp.html
I see that you did StockWatcher tutorial, these steps should cover basics. Try it on localhost first. Maybe getting globaly accessible IP is what you were originaly looking for.
The URL you pasted is the "development mode" (or "hosted mode") URL for debugging your app. For deployment, you need to compile your project (in Eclipse there's a red-colored button, and see the GWT website for more details).
If all you want is for your friend to access your debugging development run, see GWT's docs about that
pass the parameter -bindAddress 0.0.0.0 to bind the embedded server from eclipse to all network cards. compile your app with the red icon in eclipse and paste the url from the dev console without gwt.codesrv at the end
In Eclipse,
Run > Debug Configurations...
Select your project on the left panelunder Web Applications > Project Name
Select the Arguments Tab on the right panel
Under "Program Arguments:" append the argument "-bindAddress a.b.c.d" where a.b.c.d is the IP of your machine.
Restart/Run jetty
Now the URL can be accessed from a different machine on the network

Categories