Project with Guava, GWT and AppEngine - java

Is it possible to use the Guava libraries on a project done with both GWT and Google AppEngine?
I see that the individual jars (the standard Java one and the GWT compatible one) have the same package naming hierarchy. How do these integrate in a GWT+AppEngine projecT?

Yes it is possible. A few Guava classes won't be usable on AppEngine because of the restricted sandbox your app will run in, especially those in the .io package like Files (you will be able to read stuff but not write it).
Are you worried about deploying both jar files and having a conflict? If so, I think it will be fine - when you compile your GWT application, it turns into javascript, so you wouldn't necessarily be deploying the GWT compatible jar, just the normal one.

There won't be any conflict as the gwt one will be used by true DevMode client-side and the GWT compiler, the "normal " one will live in your WEB-INF/lib and be loaded (in DevMode) in a different classloader. It thus depends entirely on your project and build setup.
That being said I never tried it within the same Eclipse project. I always use distinct client and server projects, and -noserver in DevMode.

Related

Clientside GWT and Maven curious Setup

I want to setup GWT in a special mode. I only use GWT for the client side as a replacement for having to deal with JavaScript directly.
The idea is to produce a single JS file.
Since this is also part of a bigger project with multiple project pages I got a problem where to put the output of the compiler and how to setup.
The ideal setup would be placing the GWT stuff into a single project and incooperate the ouput in a different project. The question is how to do it?
Update:
The current plan is to compile the JavaScript out of GWT using a simple Java application just issuing the GWT compile command and taking the Eclipse auto-build classes as necessary input. After the sources are compiled to java script the application copies the js files (one for every supported browser) to the related destination. This way the once created js files stay static and other developers do not have to deal with GWT related build tasks and we just avoid a necessary maven fight to get things working on build.
Also the GWT project can now depend on the web project making it possible to start the web application and alter its behaviour by adding support to host mode debugging.
Does anyone know a working example?
The easiest way, if you build a WAR in the end, is to put the output of GWT in a WAR too that you can use an an overlay in the final WAR module.
Other Maven plugins could do the trick too (dependency:unpack, maven-shade-plugin, etc.)
See https://github.com/tbroyer/gwt-maven-archetypes for examples.

Redistribution of jars

I am currently compiling a list of third-party libraries used in a web application. The application is deployed in tomcat. I am wondering which of the third-party jars actually must or should be included in the distribution. In particular, I am currently wondering how to best use javax-libraries.
For instance, I would assume the javax.annotation-3.1.1.jar can be used in some standardized way, e.g., downloading it as an extension, without me including it into the distribution of my own piece of software. However, I have it included as a transitive dependency from jaxws-api which I need for web services and therefore it is included in the application's lib directory.
I understand I could use the Extension-List manifest entry to cause the target machine to download and install such jars. However, then they are visible for other applications on the same machine as well which may require other versions of the same libraries.
So, I have some questions about 3rd party libs and I would be very glad if someone could give me some hints:
What is the best practice to use third-party libraries?
Is there some best practice for the javax-libraries?
Can and should I avoid redistribution without imposing a large burden on the person installing the application?
I have to admit, I haven't understood the notion of "redistribution" here, maybe you're using some concrete application server terminology, so I'll try to provide a common answer here, assuming you have a war.
WAR (stands for Web Archive) should include all third-parties used by the application.
These reside in WEB-INF/lib folder.
Now, each Java EE server should "understand" javax libraries, because it contains the relevant interfaces. "javax" libraries usually provide interfaces and the implementation/code that works with these interfaces are provided by the application server developers.
For example for servlets technology, Tomcat (or name any web server) will contain HttpServlet abstract class inside its internal libs, it will scan your war and find where do you implement/extend it, this is how it recognizes your servlets actually.
Now, you shouldn't include servlet-api jar into your war, because its already exists in the application server.
If you're using build tools like maven, they allow to build your war so that some thirdparties will be used for compilation but won't be packed up into war.
I didn't understand why is it so difficult to install the application - in the easiest case - you throw the war into the web server and that's it.
Hope this helps

How can I include a jar file in a distinct package when deploying

I have an ant script that I use to build my J2EE application and create jar files. The problem is the following: Two jar files are necessary for the application to run.
commons-math-2.0.jar
commons-math-1.0.jar
However, I want to only use the 2.0 for a particular package inside the application with the rest of the application using 1.0. How can I build the application to only use the 2.0 version for example with a package name such as com.naurus.eventhandler.risk? Again, I'm using an Ant script, but if there's an easier way to do this sort of thing I'm willing to experiment. Thanks!
If the two jars contain different classes/packages there should be no problem to have all of them in the application classpath. It is then a matter of discipline not to use the classes from the one jar in the other package.
However I guess these two jars contain mostly the same classes/methods? There are many ways of using different versions of the same classes:
Using different ClassLoader instances. I would not qualify it as "easy", far from it means opening the door to a bunch of nasty bugs. (can be helped using a tool like OSGi)
Splitting the application in two processes, these process being launched in the same Ant target and using any mean (CORBA, RMI, REST, etc.) to communicate.
I would not advise using any of these methods though. It would probably be simpler to make all your packages use the same version. Is there any specific difficulty in doing so?
That will be problematic since both JAR files will end up in the same classpath when you deploy your J2EE application. You could achieve what you are trying to attempt with OSGI bundles, which allow each package to have separate dependencies. However, that is a relatively large refactoring of your application.
IMO, it would be best to either:
a) Duplicate the features you need from 2.0 (if the number is small and the license allows it, e.g., package individual classes).
or
b) Spend the time to upgrade the entire application to 2.0
You could use the manisfest in your jar to define the classpath.
http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
Although honestly it seems a bit convoluted, but it is your requirement.

Google App Engine Warfile Directory Structure

I just installed the Google Eclipse plugin and created my first test Web Application Project (using both GWT and GAE SDKs). The plugin autogenerated a project that had a war/ directory in it that had some peculiar subdirectories and files in it. An online search for many of these only returned other similar autogenerations of them but without any real explanation of what they are, or what they do:
war/WEB-INF/deploy/<myapp>/rpcPolicyManifest/**
war/WEB-INF/deploy/<myapp>/symbolMaps/**
war/<myapp>/symbolmanifest.json
gwt-unitCache/**
I'm also a litte confused about what the proper structure should be for a GWT WAR that is going to be deployed to GAE. What content should be packaged under war/WEB-INF/? What content should be packaged under the war/ root? Any other special considerations for GWT/GAE WARs? Thanks in advance!
Almost everything in the war/ folder is deployed to GAE. With the exception of temp-files that are used by the plugin, such as war/WEB-INF/appengine-generated/
The war/WEB-INF/ folder contains things needed to set up the GAE. This includes GAE settings for servlets, queues, logging, RPC etc. It also includes libraries that are used server-side and some GWT-mappings.
Note that the GWT libraries only are needed at compile-time and not on the server. You can put all GWT libraries in a lib/ folder outside of war/.
war/WEB-INF/deploy/<myapp>/rpcPolicyManifest/**
RPC is used to call server-methods directly from GWT-code. GWT/GAE is designed to allow RPC out-of-the-box. My guess is that the existence of a RPC policy manifest file is enough to configure GAE to allow the GWT code to use RPC, so they just put it there so you don't have to worry about it.
war/WEB-INF/deploy/<myapp>/symbolMaps/**
The plugin automatically adds the things needed here, so you don't have touch it. But the symbolMaps appear to be a dictionary used by GWT to supply different version of the app based on browser version. The first few lines in one of my symbolMap files read like this:
# { 1 }
# { 'user.agent' : 'gecko1_8' }
# jsName, jsniIdent, className, memberName, sourceUri, sourceLine
Duration,,com.google.gwt.core.client.Duration,,jar:file:/opt/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201208080121-rel-r42/gwt-2.4.0/gwt-user.jar!/com/google/gwt/core/client/Duration.java,21
Which specifies how the JavaScript symbol 'Duration' should be interpreted, given that the user agent is gecko 1.8. Each browser-compilation (FF, Opera, Safari, IE etc.) has it's own mapping, allowing for browser-specific optimizations by the GWT compiler.
war/<myapp>/symbolmanifest.json
I don't have this file in my project, but it's probably related to the GWT symbol maps mentioned above. My guess is that it defines the JavaScript symbols that the GWT app uses. If you post a snippet from it we'll be able to see if this is the case.
gwt-unitCache/**
This is a cache-folder that is only used during development. See the release notes for GWT 2.4.0:
Persistent Unit Cache: GWT Compiler and Development mode now cache
compilation artifacts between runs. This results in faster startup
time for iterative development.

How do I attach java sources to project?

I am developing a WebSphere portlet in IDEA 11. The portlet is using some methods defined on portal. I don't have the production environment compiled classes or jars on my PC but I have the source code.
Can I somehow "attach" the .java files to my projects in order to build a war file that will be deployed into the production environment? Or do I have to build the production sources first (this seems to be harder since there are lots of dependencies)?
If this is just to test something while you await the JARs/compiled classes, you can likely do this by only bringing over the API (e.g., referenced interfaces that hopefully don't have external dependencies). Then, open up the compiled WAR and remove those .class files manually to avoid collisions with the real code on the server.
The biggest problem is that you will definitely run into issues trying to limit the exposure to the real code, unless the rest of the code was setup nicely to expose an API that has very limited dependencies.

Categories