How to use org.apache.commons in GWT? - gwt

I am using GWT 2.5.0. I want to use some methods in org.apache.commons. GWT want source code also for adding external jar. So I downloaded source and class files and merge both in jar. It is not giving any error for some methods but some classes of org.apache refering other class outside this package. So it gives the following error
[ERROR] [rmchecking] - Errors in 'org/apache/commons/lang/StringUtils.java'
[ERROR] [rmchecking] - Line 237: The method isWhitespace(char) is undefined for the type Character
Is there any package in gwt that giving same facility of this org.apache.commons? or how to use this same package in gwt?

You cannot use any third party jar that is not GWT compatible. Example apache-commons.
HINT - They do not have .gwt.xml file telling GWT compiler that they have GWT compatible code.
You can however fork it and make it your own gwt compatible lib from the apache common. Example - http://code.google.com/p/gwt-commons-lang/

It is not really possible since StringUtils is based on java regular expression and the GWT regular
expression emulator is based on a javascript. You will need to write it by your own

I agree with SSR although I wouldn't be surprised if there's some messy debugging involved. It's worth mentioning that there's gwt-commons
which is still in alpha unfortunately and google guava. I use google Guava, which has a similar purpose to apache commons. It even has some features which apache commons doesn't like Optionals. Guava has a fully functional gwt version created by google that I'm using in my own project.

I've managed to convert most of Apache Commons Math 3.6.1 to compile with GWT 2.8.0, see:
https://github.com/murkle/commons-math/issues/1

Related

How to add and use a jar library in IntelliJ IDEA?

I created a new Java app from scratch in IntelliJ IDEA. Now I want to use a jar library, e.g. OpenJPA. I added the library using Project Structure -> Libraries like this:
then I tried to use annotations from that library in my Java code, but I don't get the option to import these classes. It looks like IntelliJ IDEA is not known about my library yet:
What am I doing wrong when adding this library? Is there anything more that I have to do to get it working?
After adding this library, it looks like it is automatically added to "Modules":
You have created a library, but you haven't said IntelliJ that the module must use it. Click *Modulesµ in the project structure, then select the module you want to add this library to, go to the Dependencies tab, and add the library.
EDIT:
It's simply that the annotation is not part of the jar. You need to add the jpa api jar, not only openjpa.jar
You have to add library to Module dependencies, pls check here:
Configuring Module Dependencies and Libraries

Using Play Framework 2.1.0 with NetBeans

I have started using Play 2.1.0 and I would like to be able to use NetBeans to develop Play Java applications. I'm not really interested in using the IDE to run or test the applications since I can do that from the command line (not that I would mind if I could also have IDE support for that) but I would like to be able to open and edit my project in NetBeans without getting annoying errors where they don't really exist. I am currently using NetBeans 7.3 so I first tried to use the nbplay plugin, however it wouldn't recognise all my imports or managed classes produced by Play. I then tried to import the project as Eclipse project, as described in this and this question, which worked better, but while working my way through one of Play's Java tutorials I am still getting the following errors which make it really annoying to work with NetBeans:
I get an "Expected an operand but found error" error in main.scala.html where #content is used, although I have instructed the IDE to disable HTML error checking for this file.
In my model classes I get errors because the classes do not declare a no-argument constructor and have public variables for persistent attributes.
Any other errors I have not come across yet?
Has anyone managed to make Play 2.1.0 work with NetBeans without getting any of the above errors? I could probably live with the first one (although it would really annoy me) but the rest are showstoppers.
Be aware that the Java hints can be enable or disable in Tools -> Options -> Editor -> Hints -> Select java language.
NetBeans now has Native Support for Play Framework 2.3.x and above: http://nbpleasureplugin.com/documentation/installation.html No Command line needed at all.
The most important features are:
Create, run, debug and test your app directly in the IDE
Routes files support (Syntax coloring, Syntax Error highlighting, Autocompletion, Code navigation, Show implementation code (without navigate to source), Hint to Create method when it doesn’t exist, formatting, Mark occurrences)
Scala Template support (Syntax coloring, Syntax Error highlighting, Autocompletion, Code navigation, Show implementation code (without navigate to source), formatting, Mark occurrences)
application.conf support (Syntax coloring, autocompletion with documentation, formatting, mark occurrences)
Dependency Management (Search on Maven and add them to build.sbt)
2 Code Coverage too.s supported (jacoco and scoverage)
Test Single File
SBT file minimal support
Configurations (Formatting indentation, syntax coloring, port to use, activator parameters, etc.)
*Support play version from 2.3.x and above
Note: I created this plugin.
Also I see this could help you: How do I use Play Framework 2.0 in netbeans

how to properly bundle GWT with my webapp? (was: why gwt-user-1.7.0 contains Servlet API classes)

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.

Google Web Toolkit - how to add an external .jar package

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

How to create the Scaladoc for a Maven+Scala 2.8+Java-Project with Scaladoc 2

The question says it all. I couldn't find an example on the web how to use the Scaladoc 2, especially on a Maven Project.
I'm using Maven, Scala 2.8 and some Java classes, and the Maven Scala Plugin to build the project.
But as it seems i cannot use the Maven Scala Plugin (where i could run mvn scala:doc) to create the docs because it uses VScaladoc - which has an issue on Scala 2.8/Scaladoc 2, resulting in an java.lang.reflect.InvocationTargetException
How can i build the Scaladoc for my project?
We're working on a fix, however I know DavidB and I are very short on free time, so patches are welcome! ;)
My guess (without looking into it) is that we don't have special handling for scaladoc vs. scaladoc2. The maven-scala-plugin attempts to handle Scala versions 2.6 (and less) -> 2.8 which is a pretty broad range. I'm guessing the special handling for 2.8+ versions is slightly off..
Since version 2.14.2 of maven-scala-plugin, the plugin use Scaladoc2 for project based on scala 2.8+