JUnit testing gwt web app with 2 modules - eclipse

I am currently using gwt 2.3 and smartgwtpower 2.5 nightly and using Eclipse on Linux. My web app is using common code, developed in house, and packaged to a jar called commonsmartgwt.jar. In this jar is the entry point class and has its own gwt.xml file. In my web app's gwt.xml file I inherit from the entry point class
<inherits
name="common.code.Common"/>
and I use the entry point common.code.client.Common as my web app's entry point. All my classes in my web app extend classes in the common code. Compilation and running works
fine but when I try to run a test using eclipse method Run As > GWT Junit Test, I get the following error.
Unable to find common/code/Common.gwt.xml on your classpath; could be a typo,
or maybe you forgot to include a classpath entry for source.
If I create the folder common/code/ under classes and extract the .gwt.xml file from the commonsmartgwt.jar and put it in that directory, I get a different error.
'my.package.client.MyFirstTest' was not found in module
'common.client.Common'; no compilation unit for that type was seen
Is there a way to Unit test this application. Please let me know if my situation is not clear. What if I moved the entry point from the common code to my web app? I tried following the instructions here: [Error resolution][1]
[1]: http://raibledesigns.com/rd/entry/testing_gwt_applications "Link"
but this did not work.

I had the incorrect module name returning in the getModuleName test method.

Related

Sharing RemoteService implementations between 2 GWT projects

I have been struggling a while now to try to reuse the RemoteService implementation from one GWT project into a new one.
Here's the big picture:
I have a working smartgwt-mobile project and we now decided we wanted a desktop version of the same project, using regular smart-gwt. The GUI of this new app will obviously be different but the server side code will be exactly the same.
I tried to just "borrow" the RemoteService interface, its async counterpart and the whole server package by either linking the package folders in the other project inside the new source structure (I am using Eclipse with GWT plugin) or by adding the borrowed code path as a filtered source folder to the build path, and while this satisfies the Eclipse dependency checker, the GWT compiler is unable to find the borrowed code suggesting I need to add "inherit" declarations in the module .gwt.xml file.
When I do this and recompile it now expects a second module .gwt.xml file in the root of the borrowed code which is not acceptable because it would affect the other project.
I have been reading up on the GWT module documentation but I fail to see how to implement such a scheme. It may actually be impossible to do what I am trying to achieve.
I would be willing, if that solves the problem, to create a third project that simply defines a GWT RemoteService module that then will be inherited by both the mobile and desktop smartgwt projects.
Does anybody have suggestions about how to tackle this issue?
I'l agree to "third project that simply defines a GWT RemoteService module that then will be inherited by both the mobile and desktop smartgwt projects"
Why because, I'm just already doing this. Yes that is Obviously an DAO project(DB layer) which has all my DB business logic methods there.
And its always better to maintain separate DAO layer to expose your data to services(ex.webservices).
So here's how I solved the issue.
The problem with linking to an existing GWT project source folders is that the GWT compiler always (at least that's what it looks like) expects to find a GWT module definition file (.gwt.xml). I have not been able to link in the source folders in such a way that the GWT compiler is happy, even though the Eclipse dependency resolver has no problem with it.
So I created a third project using the GWT Eclipse plugin. I unchecked the "Create Sample Code" option, so I ended up with an empty GWT project. I then selected 'Add' > 'New' > 'Other' > 'Google' > 'Module', entered a module name, e.g. 'myModule', a package name, e.g. 'com.myCompany.myModule' and clicked 'Finish'. The GWT New Module wizard created the package and a child package under it named 'com.myCompany.myModule.client' and I created 'com.myCompany.myModule.server' myself.
Now I copied the RemoteService and related classes (The implementation and Async version ), plus all the server side code the RemoteService code calls from the original project I wanted to borrow from and pasted it into the new project. Very soon I had all dependencies satisfied and I opened the Build Path dialog on the new Smart-GWT web app project and included the GWT RemoteService Module Project in the projects tab. Last thing to do was adding an inherit element to the .gwt.xml file:
<inherits name='com.myCompany.myModule.MyModule'/>
Voilá: That's all there is to it. If you select 'GWT Compile Project' It compiles and runs in dev mode without warnings.
I now still have to delete the shared code from the first project and inherit from the module, bat that is simply a repetition of what I already did.
In the end this was much less painful as I imagined it to be, so I recommend this approach.

Packaging GWT module jar

I have created a GWT-loadable module (maven) with this output jar structure (using mvn package command):
mygwtlibrary
->src/main/java
-->org.mygwtlib
---->public
------>flash.swf
-->org.mygwtlib.client
---->MyClientCode.class
However when I run a application that use this library, error shows: Error 404 for fetching the flash.swf file.
Here's the scenario:
I have setup the project properly, including the <inherits> in the gwt.xml file
When I just include the whole library project into another GWT application project then run, it works fine. That is, the files from the public folder is loaded too.
What could be the problem?
The problem is that you're trying to fetch the flash.swf file over HTTP. This is (at best) bad practice. A better approach (by no means the only alternative) would be pulling it in as a resource which lives in your code. One way to do such a thing would be using Spring's ClassPathResource (or less preferably, FileSystemResource).

My first GWT Module

I created a module to share code across a couple of projects.
I created a GWT project: Framework. I then created a module com.framework.Framework within the project. The Framework project contains both client code, in the com.framework.client packages, and server code in the com.framework.server packages.
I try to consume this by
- Adding the project to the Java Build Path
- Adding to the module's definition
When I run the consuming project, I get NoClassDefFoundErrors for Framework classes I use in the module's server code.
What am I missing?
If I jar up the Framework project's WEB-INF\classes contents and put it into the consuming project's WEB-INF\lib folder, as well as add it to the Build Path it seems to work, but I don't see a way to keep the framework classes up to date in the consuming project(s).
Please make sure that you create gwt.xml file via menu New->Module, and in this gwt.xml file, you must declare your entry point class.

GWT tries to load a deleted module

I am using Eclispe with Google plugin for AppEngine and GWT. Recently I created a test GWT module, but eventually it has been deleted from the project and I can not find any sign of it in the project now.
However, whenever I run the web app locally, I get in console the following message:
Loading modules
com.piq.exemity.Test
[ERROR] Unable to find 'com/XXXXXX/Test.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
Has anyone got any idea where it can be hiding?
Open Run Configurations... from the Run pulldown menu and go to tab Arguments. In the Program arguments box delete the path to your deleted module.
It could be there in two places -
When you invoke GWTC (via the compile option in Eclipse), the module name com.xxx.Test is passed to the compiler. This causes GWT to look for com/xxx/Test.gwt.xml file
You could have a module that inherits the module "com.xxx.Test". Check your gwt.xml file if this is the case
I think (1) is more likely the culprit.

How do I compile a module without an EntryPoint?

I have a utility module for GWT which doesn't have an UI (hence, there is no class which inherits from com.google.gwt.core.client.EntryPoint. When I try to compile this module with GWT 1.7.1, I get this error:
[ERROR] Module has no entry points defined
How do I get rid of this error? Do I really have to define a dummy entry point? How did Google ever compile their own utility modules???
Utility Jars do not need to be compiled by GWT.
If you just want to reuse this as a library in other GWT applications then you just have to jar the .class and .java files in one jar and make sure that you have a .gwt.xml that says where the client source is. If you follow the conventions (client classes in client) then you can get away with just otherwise you need to specify a tag for the client package
Then make sure that you inherit this .gwt.xml in the projects where you want to compile an entry point.
No you don't need an EntryPoint. Here is an example of one of my modules that doesn't have one:
<?xml version="1.0" encoding="UTF-8"?>
<module>
<source path="grid" />
<inherits name="com.google.gwt.user.User"/>
</module>
The short answer is you don't compile code in modules. GWT just needs them as source code. When you compile your main module (the one with the entry point) it uses the source from any other modules you have inherited in your .gwt.xml file to compile the entire project.
I'm using the gwt-maven-plugin Maven2 plugin to compile my code. I migrated the code from an old version of the maven-googlewebtoolkit2-plugin plugin. For the old plugin, I had to specify which modules were entry points like so:
<compileTargets>
<param>com.project.module.Module</param>
</compileTargets>
For the new plugin, it's
<module>com.project.module.Module</module>
Since the plugin couldn't find which modules to compile, it search for "*.gwt.xml" and compiled all of them into "UI modules" (which must have an entry point).
We've got a utilities module, which constructs & handles some common UI elements, and a bunch of javascript/json common tasks.
It looks like what we did (also migrated from the totsp plugin to the codehaus plugin somewhere along the line) was to include an entry point in the util module; it was just empty. (It includes the comment "Intentional no-op").
Then the pom just refers to the thing as a dependency.
If using eclipse GWT plugin just remove the module without an EntryPoint from the moduleslist that pops up just before compiling.