Run compiled/production javascript code of GWT maven project in Eclipse (through Jetty DevMode server) - eclipse

I am trying to run GWT compiled/production javascript code from inside Eclipse for a project generated through the gwt-maven-plugin. Each time I launch a run/debug configuration (which points to the target/MyApplication-0.0.1-SNAPSHOT folder) through the Google plugin , the DevMode server mercilessly wipes out my compiled javascripts, and start to run things in dev mode, end-result being that if I remove the gwt.codesvr parameter from the URL, I get the dreaded "GWT module 'MyModuleName' may need to be (re)compiled".
How can I run my compiled/production javascript code through the DevMode server inside Eclipse ?
The aim being:
1) to confirm that the prod javascript code behaves the same in dev mode
2) to be still able to debug the server side java code if I want
Thank you very much in advance for your feedback and your expertise.
Regards
kb

This is a known regression of GWT 2.7, but it's not clear yet whether it'll be fixed or not: https://code.google.com/p/google-web-toolkit/issues/detail?id=9021
To debug your server-side code, use "Debug As… → Maven…" and use the jetty-maven-plugin or some tomcat?-maven-plugin, e.g. using the jetty:run-exploded goal.
Or use M2Eclipse Webby or the M2Eclipse WTP integration (in other words: do what you'd do for any other Maven-based Web project, as you want to put GWT out of the equation and only use the output of its compiler)

Related

Running GWT application in production mode

I am newbie to GWT. I have built gwt maven project. To run in development mode, I first compiled project Google|Compile Project, then from command mvn gwt:run, it runs fine on
http://localhost:8888/index.html?gwt.codesvr=127.0.0.1:9997
but for production I want to access module
http://localhost:8888/index.html
When I omit gwt.codesvr= argument, I am getting error "gwt module may need to be recompiled". After Recompiling, I get the same error. Any help/pointer?
Thanks,
i run gwt project on tomcat on production mode. Jetty cant show it. Try to tun with external web module. When you are look at the IDE console title show us 'Development Mode'. Tyr with external , in any exception i can help.
You did it correctly, but as the error states, the module needs to be re-compiled (GWT Compiled). Once recompiled, Force your browser to reload (Ctrl + F5). If that doesn't work, you can look at this answer I wrote regarding cleanup of compiled output. Do what's listed there, and try running GWT compile again.
To run production mode outside Eclipse, you must do a GWT compile and create a WAR file, which you can then deploy on a Java application server such as Tomcat. This process is much easier with an ant build script.
To make an ant build script for your project:
You can easily create an ant build script by running the webAppCreator command from the directory where the GWT library is installed. That command will create a sample project just like clicking "New Web Application Project" in Eclipse, except it will also make a build.xml file.
You can run it in Eclipse by right clicking build.xml > Run As... > Ant build. By default it will run the build target. It also has a war target, which you can run to create a WAR file.
For more details on the webAppCreator, look here.

Running PlayN in HTML DevMode

I'd like to be able to run my PlayN project as a Web Application in DevMode, so that I can use a quick browser refresh to see code changes without having to recompile. From what I'm reading on the wiki and on this question it sounds like that should be possible.
I set up my project using: mvn archetype:generate -DarchetypeGroupId=com.googlecode.playn -DarchetypeArtifactId=playn-archetype -DarchetypeVersion=1.7 and importing the pom.xml into eclipse.
Here's what I can do:
Run from eclipse as a Java Application
Start the server using Maven command line: mvn -Phtml integration-test
While I can do most of my programming in Java and occasionally do the long build to test HTML, I'd love to be able to modify the code while testing HTML without recompiling.
By default, the option to run as a Web Application doesn't show up. I've tried going into the project's properties and checking the "Use Google App Engine" and "Use Google Web Toolkit" options, which creates the "Run As Web Application" option, but when I do so I get "Could not find any host pages in project XXX".
I then attempt to set a WAR directory under Properties->Google-Web Application. However, the closest thing to a WAR in the project is "src/main/webapp". I've tried using that, and I get the error: "The archive: /myproject-assets/src/main/java which is referenced by the classpath, does not exist."
I have the feeling I'm going about this all wrong. Can anyone point me in the right direction? Is what I'm doing even supposed to be possible? Thanks!
It is possible, but just know that in dev mode, playn runs very slow.
I don't know how to do this with eclipse, but with intelli IDEA, you do the following:
you need to create a module with a war artifact (to run as a server)
add the correct gwt libraries so that you can run gwt dev mode server with the aforementioned war module.
choose a GAE server (or, any gwt compatible server actually, this will be the server that runs the aformentioned war module).
run it! see this screenshot http://screencast.com/t/qK4JKvF33V
when you change code, the gwt devmode server should detect it, and automatically recompile (not sure if this needs to be in debug mode - i don't think it does).
you can try doing it via the command line, not sure if works, but this is what intellij runs (i've taken out the intellij specific bits out):
java -cp CLASSPATH_WITH_GAE_DEV_TOOLS_AND_GWT_DEV_TOOLS com.google.gwt.dev.DevMode
-war /path/to/war
-startupUrl Roborally.html com.yourgame.YourGwtEntryModule
-server com.google.appengine.tools.development.gwt.AppEngineLauncher

How do I make Eclipse and mvn appengine:devserver talk to each other?

I am in the process of switching from Google Plugin for Eclipse to the official Google App Engine Maven Plugin.
The last thing, I hope, that I cannot figure out is how to get a good debug workflow set up. When I was using GPE, I just set breakpoints and the debugger stopped there automagically, but when I run the dev server via mvn appengine:devserver, I don't think the dev server and eclipse are aware of each other.
How do I make them talk to each other?
The first option is to set up your project to use WTP as documented # https://cloud.google.com/appengine/docs/java/webtoolsplatform. This is the method I switched to.
The second option is to use two debug configurations.
The first debug configuration will run your maven target, namely appengine:devserver.
The second is a Remote Java Application configuration, and will connect the debug client to the devserver jvm.
This also requires some jvm args to be passed to the maven goal.
<!-- GAE plugin -->
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.7.5-SNAPSHOT</version>
<configuration>
<jvmFlags>
<jvmFlag>-Xdebug</jvmFlag>
<jvmFlag>-Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=y
</jvmFlag>
</jvmFlags>
<disableUpdateCheck>true</disableUpdateCheck>
</configuration>
</plugin>
Once those 3 things are in place, run the maven debug configuration, then run the debug client configuration, then exercise your application.
There is no support for hotswap yet, so if you change any non-resource files(any java source), the devserver will not see them. Resource files will get deployed(static files: html, js).
You should be executing mvn from eclipse in debug mode.
In Eclipse you can configure such maven build commands from eclipse top toolbar "Run" -> "Debug Configuration" -> "Maven Build"
Once in maven is launched in eclipse debug mode you should be able to hit the breakpoints.
Edit -
One other option is to set up Remote Debug i.e "Run" -> "Debug Configuration" -> "Remote Java Application" and listen remote debug port i.e You should ensure appengine:devserver launches with remote debug port arguments - Reference - Remote Debugging in eclipse
This question may give you a hint of the problem. The Maven appengine:devserver starts the development server on a separate process. Eclipse however is only aware of the Maven process itself (this is what you see in the debug view). In addition, since the dev server cannot be started with arguments such as a debug port, it probably can never be connected to a debugger.
The question linked suggest that there's an unofficial Maven GAE plugin which takes arguments. There's also a new ticket to enhance the official plugin and a promise by the plugin developper to implement this feature soon.
I'll see what else I can do to make the eclipse integration easier, but there is now an update to the issue filed to the appengine-maven-plugin project : http://code.google.com/p/appengine-maven-plugin/issues/detail?id=3&can=1 so take a look and see if the support for the jvm arguments can help you out.
Please let me know your experiences, I'm always in favor of things being awesome.
Answer Relevant in 2015
I created a GAE (Java) project in Sep 2015 and the following applies to this and similar projects.
I started by creating my project as on ordinary GAE maven project using the Skeleton archetype by simply following the relevant steps from Using Apache Maven - Java — Google Cloud Platform. Followed through from Requirements through to Testing your app with the development server.
After that I imported this project into Eclipse JEE (Mars) using "Import an existing Maven project". Started development.
When I needed to debug, I only had to carry out the few steps explained below.
Create a debug configuration
Go to Run -> Debug Configurations, click on Remote Java Application and create a new configuration by clicking on the New button (see screenshot, upper left corner above filter text box).
Fill in the details by choosing your particular project and giving a suitable name to the configuration as shown below (let port be 8000) and click Apply:
Uncomment some lines in pom.xml
In your project's pom.xml, find the configuration for plugin appengine-maven-plugin and uncomment the following lines:
<jvmFlags>
<jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
</jvmFlags>
Run the mvn appengine:devserver command from the command line
As the title says...
Attach the debugger from within Eclipse
Click on the little down-triangle next to the button for Debug and choose the name of the debug configuration you just set up ("HelloWorldServlet" in my example).
I roughly follow the steps # developers.google.com/appengine/docs/java/webtoolsplatform in favor of my previous method.

PlayN GWT/HTML, keeps insisting module must be (re)compiled

I created a new PlayN project from the 1.2 archetype using the command line given in the GettingStarted wiki page. I then imported this Maven Project into Eclipse, just bringing in the core, java, and html modules. If I right-click the Java project, I can choose my main class, and a window pops up with the background image shown. Note that I've done no real programming yet: I'm just using the default project configuration.
Next, I used GWT-compile through Eclipse on the HTML project, and I got no errors. When I run it as a Web application by using the provided URL (without removing the "?gwt.codesvr=127.0.0.1:9997" bit), the application runs fine aside the Eclipse Console gives a warning about being in Development Mode. (Specifically, "You are running in GWT Development Mode. For optimal performance you may want to use an alternative method.")
However, if I run the application the recommended way, by removing the gwt.codesvr parameter, then I keep getting a dialog box saying "GWT module 'testproject' may need to be (re)compiled."
After reading How do I run a maven/eclipse/GWT/playN app in production mode?, I tried doing mvn test -Ptest-html
and then pointing my browser at http://localhost:8080, but it gives the same error.
Am I doing something wrong?
(EDIT: I have no idea if this next point is significant or not, but I'll share it anyway. When I try to create a project from Eclipse, the newest PlayN archetype I can see is 1.0.3, even after telling Eclipse to update the Maven index. I'm running Eclipse Indigo.)
I guess you are running PlayN 1.0.3.
There is a bug in 1.0.3:
So you need to do the following:
Run GWT-Compile
Run the web application and get the error message: "GWT module 'testproject' may need to be (re)compiled."
Run again GWT-compile, while the Web-Application is running
Reload your browser with CTRL-F5
The important step is step 3.
Note:
You can update to PlayN 1.2 to get rid of the error. For this you have to change the file playn-showcase/pom.xml.
Change the line
<version>1.0.3</version>
to
<version>1.2</version>

GWT Post build command in Eclipse

I am starting getting used to Eclipse, but I have much more experience with Visual Studio. In Visual Studio it is possible to run auto commands after the build has finished.
Now I am creating a GWT project and several other projects at once in one solution (or workspace) in Eclipse. Some files which are compiled with the GWT project needs to be copied to another location when they have been compiled. I am currently doing this manually and would like to do it automatically. I am not doing it often, since the project works fine in debug mode (...?gwt.codesvr=localhost:9997).
But where is the location for executing a post build command for a GWT project in eclipse? Is it possible?
Just open project properties, choose 'Builders' item and click on 'New...' button.
Good question! I'm using Eclipse since about 2003, and I remember that I also wanted a functionality like that back then. However, I got so used to using ant for any serious build, that I completely forgot about it.
There is some useful ant integration in Eclipse (e.g. the ant view), and if you create your GWT project with webAppCreator you already get a few good ant targets you can build upon.
It would still be nice sometimes to have something more GUI-like to do simple multi-step builds with Eclipse. I haven't found anything like that yet, but it's absolutely possible that it exists, especially as a plugin.