title: Tomcat + OSGi + Hibernate + maven ClassNotFoundException org.hibernate.ServiceRegistry
body: <p>I've embedded OSGi framework in an Apache Tomcat server (7.0.52) using the Bridge.WAR. I can use it and run bundles on it.
  My bundles are built using maven.</p>
  
  <p>Now I would like to access to a database and get data using one bundle. I've mapped my classes by JPA annotations and I would like to use Hql queries to get data. For the data access I would like to use hibernate, I have it in the dependencies in the POM file.
  After I've built <strong>mvn clean install</strong> and embedded in the OSGi container I try to start it but it misses the classes of the <strong>org.hibernate</strong> package.</p>
  
  <p>I don't know what to do with it. Can anybody help? I'm totally lost...</p>
  
  <p>my pom.xml:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.database&lt;/groupId&gt;
      &lt;artifactId&gt;RecipePrDatabase&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;bundle&lt;/packaging&gt;
      &lt;build&gt;
          &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.4.0&lt;/version&gt;
                  &lt;extensions&gt;true&lt;/extensions&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                      &lt;instructions&gt;
                          &lt;Bundle-SymbolicName&gt;${pom.artifactId}&lt;/Bundle-SymbolicName&gt;
                          &lt;Bundle-Name&gt;${pom.artifactId}&lt;/Bundle-Name&gt;
                          &lt;Bundle-Version&gt;${pom.version}&lt;/Bundle-Version&gt;
                          &lt;Bundle-Activator&gt;com.database.service.impl.Activator&lt;/Bundle-Activator&gt;
                          &lt;Import-Package&gt;
                              org.osgi.framework;version="1.3.0",
                          &lt;/Import-Package&gt;
                      &lt;/instructions&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
              &lt;artifactId&gt;org.osgi.core&lt;/artifactId&gt;
              &lt;version&gt;1.4.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;4.3.5.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-osgi&lt;/artifactId&gt;
              &lt;version&gt;4.3.5.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.27&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.0-alpha-1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;taglibs&lt;/groupId&gt;
              &lt;artifactId&gt;standard&lt;/artifactId&gt;
              &lt;version&gt;1.1.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;jstl&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
              &lt;version&gt;3.0alpha&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-annotations&lt;/artifactId&gt;
              &lt;version&gt;3.5.6-Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;antlr&lt;/groupId&gt;
              &lt;artifactId&gt;antlr&lt;/artifactId&gt;
              &lt;version&gt;2.7.7&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;dom4j&lt;/groupId&gt;
              &lt;artifactId&gt;dom4j&lt;/artifactId&gt;
              &lt;version&gt;1.6.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.common&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-commons-annotations&lt;/artifactId&gt;
              &lt;version&gt;4.0.4.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpa-2.0-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.javassist&lt;/groupId&gt;
              &lt;artifactId&gt;javassist&lt;/artifactId&gt;
              &lt;version&gt;3.18.1-GA&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.logging&lt;/groupId&gt;
              &lt;artifactId&gt;jboss-logging&lt;/artifactId&gt;
              &lt;version&gt;3.1.3.GA&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.logging&lt;/groupId&gt;
              &lt;artifactId&gt;jboss-logging-annotations&lt;/artifactId&gt;
              &lt;version&gt;1.2.0.Beta1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.spec.javax.transaction&lt;/groupId&gt;
              &lt;artifactId&gt;jboss-transaction-api_1.2_spec&lt;/artifactId&gt;
              &lt;version&gt;1.0.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss&lt;/groupId&gt;
              &lt;artifactId&gt;jandex&lt;/artifactId&gt;
              &lt;version&gt;1.1.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;version&gt;1.7.7&lt;/version&gt;
          &lt;/dependency&gt;
              &lt;dependency&gt;
                      &lt;groupId&gt;org.jboss.spec.javax.interceptor&lt;/groupId&gt;
                      &lt;artifactId&gt;jboss-interceptors-api_1.2_spec&lt;/artifactId&gt;
                      &lt;version&gt;1.0.0.Final&lt;/version&gt;
                 &lt;/dependency&gt;
             &lt;dependency&gt;
                      &lt;groupId&gt;javax.enterprise&lt;/groupId&gt;
                      &lt;artifactId&gt;cdi-api&lt;/artifactId&gt;
                      &lt;version&gt;1.1&lt;/version&gt;
                 &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>and I use this for connect:</p>
  
  <pre><code>public void setUp() throws Exception {
          Configuration conf = new Configuration().configure("hibernate.cfg.xml");
          sr = new StandardServiceRegistryBuilder().applySettings(
                  conf.getProperties()).build();
          sessionFactory = conf.buildSessionFactory(sr);
      }
  
      public void initDB() throws Exception {
  
          session = sessionFactory.openSession();
      }
  
      public void closeDB() {
          if (session.isOpen())
              session.close();
      }
  </code></pre>