How do we add an external .jar package in Google Web Toolkit (GWT)? I have followed the steps
1) added the .jar in classpath
2) added <inherits name='org.scribe.model' /> in my test.gwt.xml
I get this error:
Loading inherited module 'org.scribe.model'
[ERROR] Unable to find 'org/scribe/model.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
[ERROR] Line 8: Unexpected exception while processing element 'inherits'
However, I have found from many sources that you need the source files to compile the client side gwt. My question is what if one cannot get a source file of the .jar package? What is the workaround?
Thanks in advance.
If it is a GWT module it is packaged with sources. Check the jar Java files should be in it.
There are two ways to use a 3rd party dependency in your GWT application.
It is either a GWT module already which contains a module xml file along with the source files. In this case you just refer to it using inherits.
Or it is some regular 3rd party dependency in this case you need the source code and you also have to play with the package names since GWT requires source code to be under client package. Even you do so since the artifact is not developed GWT in mind, it might most likely contain code that is not allowed by GWT, e.g. you cannot use Threads in GWT.
There is no workaround. You need source files.. At least you can decompile class files..
My suggestion would be to handle intense logic on server side (within server package)
On the server side , you can use classes that are not supported by GWT front-end (classes in client package).
E.g
When I tried to use BufferedReader in client, I got exceptions, I then moved it to server package and retuned the result. The same was for RE which didn't work in client code too.
Keep your client code as simple as possible.
Hope this helps.
Cheers
PB
Related
So I am having issues deploying code to my local websphere server (imagine the dred I have for installing it to my test server).
I get a java.lang.ClassNotFoundException when I attempt to run the application.
So after googling around it seems as though I need to add entries into one of the above files. Problem is, there doesn't seem to be good examples of how to do that.
In the Manifest.mf file, do I need to add the fullpath to where I expect the jar to be? Does anybody have a good example of a deployment.xml/libraries.xml? How do I translate what is in my project classpath to entries into those various files?
Start with 'Websphere Class Loaders'.
Usually the order to load/find a class/resource is :
Current Module(war/jar/sar) --> (if not found then look inside) -->
Another Module in EAR (via manifest.mf) --> (if not found then try to load it from) -->
Common shared library (libraries.xml) (or) Extensions library -->
(if not found, then throw the error Class not found/No class Def found error).
Manifest.mf
Using this file you could point to the module/location directly to load the required classes/resources.
libraries.xml
Here you can define and maintain the shared libraries which can be used across many JVM's (like single jar file can be referenced from multiple jvm instances). Refer this for more information.
In my experience, I try to avoid using manifest.mf files, and refer the library jar files from shared library 'libraries.xml' file. (or) if you are trying to learn the Web sphare, then just include the jar files in lib/ folder of your package.
The GWT documentation states that all the source code for compilation to JavaScript on the client-side must be in a subpackage of the gwt.xml file. How does this work for when one references third party libraries?
Specifically, if I have a library foo.jar and I want to use some POJOs (which are Serializable) and do not suck in any non-Serializable code, how can I use these POJOs? How do I tell GWT where the source code is for them?
Remember too that the GWT compiler needs actual Java source to compile to javascript, so it isn't enough that the classes are available and that all are serializable. For RPC to send the classes over the wire, they must be able to be used as JS when they get to the client.
That said, take a look in gwt-user, at the module javax/validation/Validation.gwt.xml. This file is put there so that other packages in javax.validation - even in other jars - can be compiled into JS for client-side validation. if you have a jar (and sources) on your classpath with code in com.thirdparty.pojos, you can create a module file in your own project in that same dir in your own source (something like com/thirdparty/pojos/ThirdParthRpc.gwt.xml, and put a <source path="" /> element in it to indicate that the entire package is legal for translation to JS. There will likely be some files that cannot be translated - use the exclude tag to deal with those.
If you have control over packaging foo into foo.jar, and you have all the sources, then it's easy.
If you have a packaged foo.jar, and happen to have the source code, then you need to expand the foo.jar, copy the source into the exploded .jar directory, generate a simple GWT module.xml file and add an tag to your project’s module.
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.
Does anyone know any sane reason for such bundling decision? Google engineers act wisely in most cases, so this kinda surprized me.
This would cause collisions with other versions of servlet API pulled via Maven dependencies:
webapp classpath will likely contain
version which is bundled with GWT;
container may refuse to load the GWT
jar as it contains the javax.servlet
package;
in most cases this will
likely deviate classpaths across your
IDE's debugger and the really
executing VM.
Link to the jar in question (just so you see the same thing after unzipping as I do, if you don't believe that GWT contains servlet API classes in the same jar):
http://repo1.maven.org/maven2/com/google/gwt/gwt-user/1.7.0/gwt-user-1.7.0.jar
You shouldn't be including gwt-dev.jar or gwt-user.jar in your war file. You only need gwt-servlet.jar in your war, and that too only if you are using RPC. If you notice, gwt-servlet.jar (ironically) does not contain any of the servlet classes.
gwt-dev.jar contains the compilers and linkers. Your code will never need this to compile.
gwt-user.jar contains the gwt framework that ultimately gets translated to javascript. You only need this during development mode.
gwt-servlet.jar contains the server side code that is needed if you use RPC framework. This is the only jar that should be present in your war file.
The reason the classes are in the package is to provide a full working solution for users who only use the gwt-user file in development. Without it GWT RPC wouldn't compile. This is/was the general view of the GWT team as can be found in this lively discussion on the GWT issue tracker: http://code.google.com/p/google-web-toolkit/issues/detail?id=3851
However, GWT 1.7 also contains the javax source files, which can cause additional problems. For example for maven and probably also for the points you mention. This was addressed in the GWT issue and in later version of GWT the javax source files have been removed from the gwt-user jar file.
For deployment you should use the gwt-servlet jar, which doesn't contain the javax classes or any other third party libraries. In the past several it could happen GWT files designed for client side use also used on the server side were missing from the gwt-servlet jar file. Losts of these issues have been addressed and classes were added to the servlet jar file. If you still find a GWT class you need is missing from the gwt-servlet you should file an issue report. In your case, assuming you're using 1.7, it might mean to upgrade to a newer version of GWT.
My project contains 2 source folder, one is generic J2EE application another is smartCleintGWT,
I want to use some already existing DTO classes from first source folder (src)
Note that class used on client side and on server side of GWT project!
When I do that I getting error
[ERROR] Errors in 'file:/C:/..Projects/Admin/DMX/src_console/com/ho/nod/client/AdminRPC.java'
[ERROR] Line 7: No source code is available for type com.dmx.synch.server.descriptors.DMXLicense; did you forget to inherit a required module?
Source is available obviously; is there any way to import all that into GWT?
PS In the future 2 source folder will be separated into 2 projects...I hope it wont be that complicated as well.
You can find in the good docs:
Modules can specify which subpackages
contain translatable source, causing
the named package and its subpackages
to be added to the source path. Only
files found on the source path are
candidates to be translated into
JavaScript, making it possible to mix
client-side and server-side code
together in the same classpath without
conflict. When module inherit other
modules, their source paths are
combined so that each module will have
access to the translatable source it
requires.
To add another subpackage add <source path="package"/> in your host file (*.gwt.xml). From the log you posted, it seems you have to add source from the com.dmx.synch.server package.
Most RPC problems are related to Serializablity of the DTO in question, can you need to ensure that the classes have default constructor and also check if the Module definition file i.e. .gwt.xml file has source element pointing to these packages.
GWT only looks for source code in the client package by default, so if you have added new packages you must specify this in your *.gwt.xml file.
Add something like: source path='your_top_dir' in XML format.