In my GWT application, I made a control to display/edit a numerical value with an associated unit (for example to convert meters <-> feet).
How could I use the JScience library (jsr-275 implementation) in the client part ?
I try to add it to my project but it didn't compile:
No source code is available for type java.text.ParsePosition
Thanks for your help.
This is not a problem with the JScience library as such.
GWT compiles java to javascript and as such needs access to the java source code. Also, not all of the JDK classes are available in the GWT emulation library, and ParsePosition (indeed all of java.text.*) is one of them...
It is not clear from your stacktrace excerpt whether you have used ParsePosition directly or it is the JScience library that does, but either way you will have to rewrite your code to not use that class on the client side (if possible) or perform the conversion on the server side, where the GWT JRE restrictions do not apply.
Have a look at JRE Emulation Reference for a complete overview of what's available to you.
Cheers and good luck,
Related
I was reading this article:
http://www.java.com/en/download/faq/deployment_toolkit.xml
and I get confused about the purpose and use of the DT Plug-in and the deployJava.js.
I always believe that the Deployment Toolkit is the set of functions of the deployJava.js file (like this link says: http://blogs.oracle.com/thejavatutorials/entry/deployment_toolkit_101) but according to the article there are two parts of the Deployment Toolkit: the Plug-in and the interface for the developer.
I'm asking about all of this because the deployJava.js fails to detect the appropriate version of Java in some of the machines of our users and I was wondering if the DT Plug-in could help us improve the detection, but I don't know how exactly it detects the Java version and when it does it or how can I use it to solve detection problems?
Most of this doubts are driven by the question in the article:
"Does deployJava.js work if the Java DT Toolkit plug-in is disabled?
Yes, deployJava.js contains some pure JavaScript functions, which will continue to work even if the Java DT Toolkit plug-in is disabled."
So... why do I need the deployJava.js if the DT Plug-in exists or vice versa?
Any help on this matter would be very appreciated.
Thank you very much.
If anyone has doubts about it, I've posted this question in the oracle forum and this was the reply:
Deployment toolkit is combination of native library and javascript
helpers. javascript is the only official public API to native library.
JRE is installed with DT native library that is left on the system if
JRE is uninstalled. As of now DT native library is only available on
Windows.
Javascript helper functions use native library if it is available but
many actions can be performed (with degraded accuracy, etc.) even if
native library is not present.
Note that there is new Javascript APIs for DT as alternative to
deployJava.js. it is called
[dtjava.js|http://download.oracle.com/javafx/2.0/deployment/deployment_toolkit.htm#BABJHEJA]
and is primary API for JavaFX applications. However, it also supports
pure Java apps and likely will be main JS API for DT going forward
(some more testing and bug fixing may be needed).
Hope this helps to clarify the relationship.
Thxs to igor
Link to oracle post: https://forums.oracle.com/forums/message.jspa?messageID=9932788#9932788
I compiled the version in svn tagged as gwt2.4rc. Now there are a
couple of more libraries than I had the last time. Are the any
instructions on which library is needed for what? I tried it with only
the standard libraries (servlet, servlet-deps, user) but I get the
following error when a requestfactory call is made:
java.lang.NoSuchMethodError:
com.google.gwt.core.client.impl.WeakMapping.setWeak(Ljava/lang/
Object;Ljava/lang/String;Ljava/lang/Object;)
I tried declaring the requestfactory-client and requestfactory-server
jars as dependencies, but i doesn't help. I am using maven to manage
my dependencies.
I would go back to 2.4 beta, but I need the drag&drop features that
were introduced later.
Does anybody has an idea what could be wrong? or any hints how i can
dig deeper into this? I spend a lot of time trying to figure this out
but without any success :(
Do I need to provide more information?
Regards,
arne
Are you sure you deployed the 2.4-rc1 gwt-servlet.jar in your war/WEB-INF/lib ? Also, make sure you override the SDK for the gwt-maven-plugin: http://mojo.codehaus.org/gwt-maven-plugin/user-guide/using-different-gwt-sdk-version.html
That being said:
when using Maven, you shouldn't use gwt-servlet-deps but instead reference org.json:json and javax.validation:validation-api
requestfactory-server can be used instead of gwt-servlet if you only use RequestFactory on the server-side (no GWT-RPC, no SafeHtml, no RegExp, etc.); requestfactory-client is to be used for Java clients (such as Android), not the case here.
For GWT client side you need Java source code so i got that idea to convert scala code to java code.
How can i archieve this conversion?
Or is there a production ready possibility to use scala directly?
Thanks for any help!
It can't be done because Scala compiles directly to byte code, not Java. Compiling to byte code is much easier than generating Java and besides, there's a lot of stuff the byte code allows that is forbidden by Java the language, such as not declaring checked exceptions.
There's a project going on at http://scalagwt.gogoego.com/ to generate a "java-like" language from Scala that GWT can read. It seems to be moving along nicely and I know Lex Spoon is involved with it. I know they briefly considered the other possibility of decompiling the generated Java but dropped that path quickly after determining that too much information was lost in that process.
If you only want to use Scala on the backend and write the client in Java, that's always been possible and works fairly well in Eclipse.
Some work has been done to allow GWT to be written in Scala, by an intern on the GWT team last summer. See http://www.youtube.com/watch?v=_1GjgFjX5gE
I have some amount of messages which are coming to my client from the server.
Every messages have an unique key which is possible to be duplicated in messages I have already received.
Which collection can I use in GWT to avoid duplication?
HashMap seems not to be a case for GWT. Is there any other way to organize it?
You can use the standard java.util.HashMap in GWT without problems. Be sure you haven't accidentally imported the com.google.gwt.dev.util.collect.HashMap. It happened to me several times while using Eclipse's Organize imports feature..
For questions like this, you should take a look at the GWT JRE Emulation Reference. It contains the java classes of the Java runtime library that can be automatically translated by GWT. The link points to the JRE ER for GWT 1.6. to show you that HashMap wasn't just included in the latest version. (The JRE ER for the latest version can be found here)
As xor_eq points you should check the GWT JRE Emulation Reference Check the link to the latest version (or the version that you're running). The support for for HashMap was added to GWT sometime ago (in 2.0 I think), so you should have no problem.
I am using GWT 2.0.4 and want to perform the trivial operation of replacing string.
Something which can be done using java.lang in java, and since GWT doesn't support Java libraries and I want to avoid writing a JSNI, is there a way to do a string replace, Is there anything i am missing or might not knw?
Latest version of GWT,which is just an RC, 2.1 has a library called com.google.gwt.regexp which have something as simple as
originalString.replace(Expression String, Replacement String)
but since it is RC, I cannot use it here, Any suggestions are appreciated and Thanks for helping.
String.replaceAll() (any any java.lang method listed here) works in GWT.
Furthermore, it's incorrect to say "GWT doesn't support Java libraries" -- GWT supports lots of Java libraries, and many that aren't immediately usable can be made GWT compatible with a little work.