User Tools

Site Tools


vaadin_7_osgi_web_application

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
vaadin_7_osgi_web_application [2014/03/11 16:07]
mihael [Installing Vaadin]
vaadin_7_osgi_web_application [2015/04/29 13:37] (current)
mihael
Line 1: Line 1:
 ====== Vaadin 7 OSGi Web Application ====== ====== Vaadin 7 OSGi Web Application ======
-[[http://​vaadin.com | Vaadin 7]] is a Servlet based Java web framework. And as most OSGi container support Servlet based web applications very well. So this should be a match made in heaven. But their are some minor things one will stumble upon when trying to run a Vaadin application inside an OSGi container. One of those things is always the classpath.+ 
 +<​note>​ 
 +This was tested with Vaadin 7.3.3. This guide cannot be used exactly as it is for Vaadin 7.4. See [[vaadin_7.4_osgi_web_application|Vaadin 7.4 OSGi Web Application]] for a using Vaadin 7.4. 
 +</​note>​ 
 + 
 +[[http://​vaadin.com | Vaadin 7]] is a Servlet based Java web framework. And as most OSGi container support Servlet based web applications very well this should be a match made in heaven. But their are some minor things one will stumble upon when trying to run a Vaadin application inside an OSGi container. One of those things is always the classpath.
  
  
 ===== From Vaadin 6 to Vaadin 7 ===== ===== From Vaadin 6 to Vaadin 7 =====
-Some major changes have been made to the Vaadin API from version 6 to 7 but also some structural changes to the deployment. When Vaadin 6 was comfortable ​packaged into one jar Vaadin 7 comes with multiple jars. The Vaadin 6 jar didn't depend on any other jar which was very convenient. In contrast Vaadin 7 depends on dozens of other jars (some of them not OSGi ready out of the box).+Some major changes have been made to the Vaadin API from version 6 to 7 but also some structural changes to the deployment. When Vaadin 6 was comfortably ​packaged into one jar Vaadin 7 comes with multiple jars. The Vaadin 6 jar didn't depend on any other jar which was very convenient. In contrast Vaadin 7 depends on dozens of other jars (some of them not OSGi ready out of the box).
  
  
Line 29: Line 34:
  
 <sxh java title=OsgiVaadinServlet>​ <sxh java title=OsgiVaadinServlet>​
-package test.vaadin7;​ 
- 
-import com.vaadin.server.VaadinServlet;​ 
- 
 public class OsgiVaadinServlet extends VaadinServlet { public class OsgiVaadinServlet extends VaadinServlet {
  
     private static final long serialVersionUID = -4733496883901044844L;​     private static final long serialVersionUID = -4733496883901044844L;​
  
 +    @Override
 +    protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration)
 +                    throws ServiceException {
 +
 +        VaadinServletService service = new VaadinServletService(this,​ deploymentConfiguration) {
 +            private static final long serialVersionUID = 1L;
 +
 +            @Override
 +            public ClassLoader getClassLoader() {
 +                return OsgiVaadinServlet.class.getClassLoader();​
 +            }
 +
 +            @Override
 +            protected List<​RequestHandler>​ createRequestHandlers() throws ServiceException {
 +                ClassLoader actual = Thread.currentThread().getContextClassLoader();​
 +                try {
 +                    Thread.currentThread().setContextClassLoader(DefaultBroadcaster.class.getClassLoader());​
 +                    return super.createRequestHandlers();​
 +                }
 +                finally {
 +                    Thread.currentThread().setContextClassLoader(actual);​
 +                }
 +            }
 +        };
 +        ​
 +        service.init();​
 +        ​
 +        return service;
 +    }
 } }
 </​sxh>​ </​sxh>​
Line 116: Line 146:
 </​sxh>​ </​sxh>​
  
 +==== vaadinbootstrap.js ====
 +The file //​vaadinbootstrap.js//​ is located in the //​vaadin-server//​ jar in the folder //VAADIN//. The file should be copied from the vaadin-server jar to the folder ''​src/​main/​webapp/​VAADIN/''​.
 +
 +==== Classpath ====
 +Vaadin expects some things to be on the classpath of the application,​ like themes and compiled resources. To get this working in a simple way is to include these in the war (see Embed-Dependency in pom.xml) and add them to the Bundle-ClassPath entry in the manifest file.
 +
 +  Bundle-ClassPath:​ .,​WEB-INF/​classes/,​WEB-INF/​lib/​vaadin-themes-7.3.3.jar,​WEB-INF/​lib/​vaadin-client-compiled-7.3.3.jar
 +  ​
 ===== Building ===== ===== Building =====
 Building the web application bundle with maven is no more than doing a  Building the web application bundle with maven is no more than doing a 
Line 121: Line 159:
   mvn clean package   mvn clean package
  
-The target folder ​should contain ​the bundle (war) file. +The "target" ​folder ​contains ​the bundle (war) file. 
  
 ===== Deployment ===== ===== Deployment =====
Line 145: Line 183:
 Sadly not all libraries delivered with the Vaadin All-In-One archive are provided with a valid OSGi manifest header. But for most use cases a subset of libraries is sufficient enough. For this demo only the following libraries are needed: Sadly not all libraries delivered with the Vaadin All-In-One archive are provided with a valid OSGi manifest header. But for most use cases a subset of libraries is sufficient enough. For this demo only the following libraries are needed:
  
-  * jsoup-1.6.3.jar +  * json-0.0.20080701.jar         
-  * commons-collections-3.2.1.jar +  * flute-1.3.0.gg2.jar ​          
-  * commons-codec-1.7.0.jar +  * atmosphere-runtime-2.1.2.vaadin6.jar 
-  * commons-io.2.4.0.jar +  * org.apache.commons.beanutils-1.8.3.jar ​                
-  * commons-lang3-3.1.0.jar +  * org.apache.commons.codec-1.7.0.jar ​          ​ 
-  * vaadin-server +  * org.apache.commons-collections-3.2.1.jar ​     
-  * vaadin-client +  * org.apache.commons.io-2.4.0.jar ​              
-  * vaadin-client-compiled +  * org.apache.commons.lang3-3.1.0.jar ​          ​ 
-  * vaadin-shared +  * vaadin-slf4j-jdk14-1.6.1.jar 
-  * vaadin-shared-deps +  * jsoup-1.6.3.jar ​                   ​ 
-  * vaadin-themes+  * guava-16.0.1.vaadin1.jar ​              
 +  * streamhtmlparser-jsilver-0.0.10.vaadin1.jar 
 +  * vaadin-shared-7.3.3.jar 
 +  * vaadin-server-7.3.3.jar 
 +  * vaadin-client-7.3.3.jar
  
-<note tip>Some of the libraries in the Vaadin archive have no OSGi manifest header entries, check for Bundle-* entries. OSGi versions of these libraries can be downloaded here (TODO) or from the [[http://​search.maven.org ​|| Maven Repository]].</​note>​+<note tip>Some of the libraries in the Vaadin archive have no OSGi manifest header entries, check for Bundle-* entries. OSGi versions of these libraries can be downloaded here (TODO) or from the [[http://​search.maven.org | Maven Repository]].</​note>​ 
 + 
 +<note important>​The Vaadin All-In-One archive comes with an incompatible json library. The bundle version of the library is not what the rest of the vaadin library expects. The Bundle-Version and the version on the Export-Package entry needs to be updated to something like 0.0.20141029 
 + 
 +  Export-Package:​ org.json;​version="​0.0.20141029"​ 
 +  Bundle-Version:​ 0.0.20141029 
 +</​note>​
  
 === Installing Demo === === Installing Demo ===
-Just copy the test.vaadin-x.x.x.war to the deploy folder ​are you are done. +Just copy the test.vaadin-x.x.x.war to the deploy folder ​and you are done. The web application is available under the path which is specified in the manifest with the //​Web-ContextPath//,​ in this example ''/​test.vaadin7''​.
  
 +So point the browser to ''​http://​localhost:​8181/​test.vaadin7''​.
 === Checking the web application === === Checking the web application ===
 Apache Karaf uses Jetty as its HTTP server. By default it uses the port 8181. You can check this by either pointing your browser to http://​localhost:​8181 or by using netstat. Apache Karaf uses Jetty as its HTTP server. By default it uses the port 8181. You can check this by either pointing your browser to http://​localhost:​8181 or by using netstat.
Line 172: Line 221:
  
  
 +===== Stylesheet Compiling =====
 +If a CSS style is used or one of the predefined styles then everything is alright and should work. But if you are using your own style (or extending an existing one) than normally Vaadin would compile it on the fly during the first call of the servlet. But that ends in a nice error message.
 +
 +  java.lang.NoClassDefFoundError:​ com/​vaadin/​sass/​internal/​ScssStylesheet
 +  ​
 +But the Book of Vaadin explains nicely how to compile the stylesheet before the deployment.
 +
 +For myself the easiest way was to manually compile it with the following command
 +
 +  java -cp "/​my/​path/​to/​vaadin-all-7.3.3/​lib/​*":"/​my/​path/​to/​vaadin-all-7.3.3/​*"​ com.vaadin.sass.SassCompiler styles.scss styles.css
 +
 +  ​
 ===== Open Questions ===== ===== Open Questions =====
 The Vaadin Push support has been tested in this setup. It may need some additional classes which has to be available on the bundle classpath. The Vaadin Push support has been tested in this setup. It may need some additional classes which has to be available on the bundle classpath.
Line 189: Line 250:
  
  
-{{tag>​devel java}}+{{tag>​devel java vaadin}}
vaadin_7_osgi_web_application.1394554027.txt.gz · Last modified: 2014/03/11 16:07 by mihael