Friday, December 16, 2011

Run a Google Web Toolkit 2 project on Apache Karaf/ServiceMix

To simplify the development of Web projects on Apache Karaf/Apache ServiceMix, we have created archetypes to setup WAR or WAB projects. They are very basic but they can be enriched with framework like Struts 2, Wicket, plain JSP or MyFaces JSF as they are currently supported on Apache Karaf - ServiceMix.

For the GWT users, it exists now an archetype which will create a GWT 2.4 project. To create such a project, you must generate a project from the archetype

mvn archetype:generate \
   -DarchetypeGroupId=org.ops4j.pax.web.archetypes\
   -DarchetypeArtifactId=wab-gwt-archetype \
   -DarchetypeVersion=2.1.2 \
   -DgroupId=com.mycompany \
   -DartifactId=hello \
   -Dversion=1.0



build next the WAB using hello/mvn clean install

and deploy it on Apache Karaf



Verify that the web site is well registered :



Next, you can navigate to your application in your browser and click on the button to say Hello.




Remark : A WAB project is nothing more than a WAR excepted it is packaged as a bundle file, that we have removed the WEB-INF/lib dependencies and create a MANIFEST file containing the OSGI instructions.


8 comments:

Christian said...

Hi, thanks for this post. I just tried this. Building works fine, but when i try to follow the instructions in the README i get errors for:

install -s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.json/20090211_1-SNAPSHOT
install -s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.gwt-dev/2.4.0_1-SNAPSHOT
install -s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.gwt-user/2.4.0_1-SNAPSHOT

java.lang.RuntimeException: URL [mvn:...] could not be resolved.

Do i have to add a certain maven repo?

Thanks

cmoulliard said...

Apache Maven repo should be used to get the servicemix bundles as they are not yet published (https://repository.apache.org/content/repositories/snapshots/)

amasse said...

I'm trying to install the 2 gwt 2.4.0_1 bundles (release version now) and I have the following issue :


org.osgi.framework.BundleException: Unable to resolve module org.apache.servicemix.bundles.gwt-user [229.0] because it exports package 'com.google.gwt.core.client' and is also exposed to it from org.apache.servicemix.bundles.gwt-dev [235.0] via the following dependency chain:

org.apache.servicemix.bundles.gwt-user [229.0]
import: (package=com.google.gwt.util.tools)
|
export: package=com.google.gwt.util.tools; uses:=com.google.gwt.core.client
export: package=com.google.gwt.core.client
org.apache.servicemix.bundles.gwt-dev [235.0]

Any idea ?
Thanks

Brent said...

We are trying to use this kind of development here, but it is seemingly somewhat slow because with even a small javascript change, or JSP change, etc, I have to reinstall the bundle to the karaf container. I liked it better in Tomcat how I could try things out quite quickly and javascript changes were immediate, and tomcate would recompile JSP files when the file changes. We are trying a kind of hybrid of this where all of our web services, etc are deployed to the karaf container, and the UI components are deployed to tomcat, but I continually get cross site scripting errors when my javascript attempts to hit the webservices in the karaf container.
Do you have any thoughts about how me and my team could develop quicker?

Thirlan said...

Is this still the suggested way to deploy a GWT product into servicemix? If so what is the repository I should access for the archetype? I keep getting the error message "The desired archetype does not exist (org.ops4j.pax.web.archetypes:wab-gwt-archetype:2.0.0-SNAPSHOT)" no matter which repo I point to.

cmoulliard said...

Hi Thirlan,

As OPS4J project has released the gwt-archetype 2.1.2, you should use now this version by example now (http://repo1.maven.org/maven2/org/ops4j/pax/web/archetypes/wab-gwt-archetype/2.1.2/) instead of the SNAPSHOT

Regards,

Charles

Unknown said...

Thx for Lukasz Dywicki explanation -->

You don't need gwt-user at runtime because:
- Java application written with GWT is compiled to Java Script
- Java .class files are not needed at all to run it
- Java Script do not depend on any Java classes

What you actually need is only to collect generated resources package them in jar with additional classifier and install it instead of compiled Java artifact. Below you might find example of maven-jar-plugin configuration which catches generated artifacts from GWT project and package it with -gwt classifier.


org.apache.maven.plugins
maven-jar-plugin
2.3


gwt

jar


${basedir}/target/${pom.artifactId}-${pom.version}/Application
gwt



Unknown said...

Thx for your comment Lukasz Dywocki -->

You don't need gwt-user at runtime because:
- Java application written with GWT is compiled to Java Script
- Java .class files are not needed at all to run it
- Java Script do not depend on any Java classes

What you actually need is only to collect generated resources package them in jar with additional classifier and install it instead of compiled Java artifact. Below you might find example of maven-jar-plugin configuration which catches generated artifacts from GWT project and package it with -gwt classifier.


org.apache.maven.plugins
maven-jar-plugin
2.3


gwt

jar


${basedir}/target/${pom.artifactId}-${pom.version}/Application
gwt