5 Replies Latest reply on Mar 17, 2015 11:29 AM by sdotlittlenail

    Problem: using modeshape with JBoss JNDI

    m.jawwad

      Hi,

       

            I am new to ModeShape and was going through the tutorials for modeshape configurations etc. I read about working of Modeshape on JBoss AS 7 (JNDI). So I decided to give it a try. I followed all the steps provided on the page: https://docs.jboss.org/author/display/MODE/ModeShape+and+JBoss+AS7

       

      But unfortunately when I try to access modeshape through a simple servlet using the following code:

       

      --
      InitialContext context = new InitialContext();
      
      javax.jcr.Repository repository = (javax.jcr.Repository) context.lookup("jcr/sample");
      
      

      --

       

      , I get the following exception:

      ----------------------------------------------------------------------------------------------------------------------------

      java.lang.ClassCastException: org.modeshape.jcr.JcrRepository cannot be cast to javax.jcr.Repository

      com.virtualcode.modeshape.servlet.modeshapedemo.doGet(modeshapedemo.java:72)

      javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

      javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

      -----------------------------------------------------------------------------------------------------------------------------

       

      Any idea what I might be missing or what I might be doing wrong?

       

      Thanks in advance.

        • 1. Re: Problem: using modeshape with JBoss JNDI
          hchiorean

          Hi,

           

          Assuming your servlet is packaged in a .war file, make sure your war file does not include neither jcr-2.0.jar nor modeshape-jcr-api.jar nor any other ModeShape jars (if you're using Maven to build, those should be provided).

           

          Your web application should use the same jars that are installed/deployed in the AS7 server via the ModeShape module. In your war file,  just to add a dependency to those modules, either via a MANIFEST.MF, or a jboss-deployment-structure.xml file:

           

          <jboss-deployment-structure>

              <deployment>

                  <dependencies>

                      <module name="javax.jcr"/>

                      <module name="org.modeshape.jcr.api" services="import"/>

                      <module name="org.modeshape" services="import"/>

                  </dependencies>

              </deployment>

          </jboss-deployment-structure>

          • 2. Re: Problem: using modeshape with JBoss JNDI
            m.jawwad

            Hi,

             

                      Thanks a lot for the response. Yes my servlet is packaged in a .WAR, but I am not using Maven. Also as recommended, I removed modeshape  and jcr2.0.jars  but the result is the same. i.e.

                       java.lang.ClassCastException: org.modeshape.jcr.JcrRepository cannot be cast to javax.jcr.Repository

             

                      Currently deployed jars (in the WAR) are:

            -----------------------------------------------------------

            avro-1.5.1.jar

            c3p0-0.9.1.jar

            cglib-2.2.jar

            commons-beanutils-1.8.0.jar

            commons-codec-1.5.jar

            commons-collections-3.2.1.jar

            commons-compress-1.4.1.jar

            commons-dbcp-1.3.jar

            commons-digester-1.7.jar

            commons-fileupload-1.2.1.jar

            commons-io-1.4.jar

            commons-lang-2.6.jar

            commons-logging-1.1.jar

            commons-pool-1.5.4.jar

            concurrent-1.3.4.jar

            core-renderer-minimal.jar

            core-renderer.jar

            cssparser-0.9.5.jar

            dom4j-1.6.1.jar

            guava-12.0.jar

            hibernate-commons-annotations-4.0.1.Final.jar

            hibernate-search-engine-4.1.1.Final.jar

            infinispan-core-5.1.2.FINAL.jar

            jackson-core-asl-1.9.2.jar

            jackson-mapper-asl-1.9.2.jar

            jakarta-regexp-1.4.jar

            jboss-logging-3.1.0.CR2.jar

            jboss-marshalling-1.3.6.GA.jar

            jboss-marshalling-river-1.3.6.GA.jar

            jboss-transaction-api_1.1_spec-1.0.0.Final.jar

            jcr-2.0.jar     (removed)

            jgroups-3.0.6.Final.jar

            joda-time-1.6.2.jar

            jsf-api.jar

            jsf-impl.jar

            jstl.jar

            lucene-core-3.5.0.jar

            lucene-regex-3.0.3.jar

            modeshape-common-3.1.3.Final.jar (removed)

            modeshape-jcr-3.1.3.Final.jar (removed)

            modeshape-jcr-api-3.1.3.Final.jar (removed)

            modeshape-schematic-3.1.3.Final.jar (removed)

            modeshape-sequencer-text-3.1.3.Final.jar (removed)

            modeshape-sequencer-xsd-3.1.3.Final.jar (removed)

            modeshape-sequencer-zip-3.1.3.Final.jar (removed)

            paranamer-2.3.jar

            poi-3.8.jar

            poi-ooxml-3.8.jar

            poi-ooxml-schemas-3.8.jar

            poi-scratchpad-3.8.jar

            rhq-pluginAnnotations-3.0.4.jar

            richfaces-components-api-4.2.2.Final.jar

            richfaces-components-ui-4.2.2.Final.jar

            richfaces-core-api-4.2.2.Final.jar

            richfaces-core-impl-4.2.2.Final.jar

            sac-1.3.jar

            snappy-java-1.0.1-rc3.jar

            tika-core-1.2.jar

            tika-parsers-1.2.jar

            vorbis-java-core-0.1-tests.jar

            vorbis-java-core-0.1.jar

            vorbis-java-tika-0.1.jar

            xmlbeans-2.3.0.jar

            xz-1.0.jar

            --------------------------------------------------------

             

            Any idea what else I might be missing?

             

             

            Thanks again.

            • 3. Re: Problem: using modeshape with JBoss JNDI
              hchiorean

              Do you need any of the above jars directly in your code ? (e.g. I'm seeing a lot of tika + dependencies there, which I'm not sure you need). Normally, most (if not all of these jars) are already deployed & installed in application server (some of them are present out-of-the-box, some are present after you've installed the ModeShape kit). So normally in your web application you just need a deployment descriptor which lists the correct module dependencies.

               

              What does you deployment descriptor look like ? (either MANIFEST.MF or jboss-deployment-structure.xml)

              1 of 1 people found this helpful
              • 4. Re: Problem: using modeshape with JBoss JNDI
                m.jawwad

                Hi.

                 

                      Please ignore my last reply . There problem was that I was missing jboss-deployment-structure.xml in the WAR. After reading your reply, I checked and added the file. And now the code is working. Also about all the JARs, they were all added from the modeshape-3.1.3-dist download and yes most of them are not needed so I am removing jars that are not required.

                 

                       Thanks a lot for the help.

                • 5. Re: Problem: using modeshape with JBoss JNDI
                  sdotlittlenail

                  Hi,

                   

                  instead of a WAR  I'm using EJB as packaging type to reuse the jar file (containing the modeshape functionality) within a separate project.

                   

                  Unfortunately I'm getting the same error message on runtime:

                  java.lang.ClassCastException: org.modeshape.jcr.JcrRepository cannot be cast to javax.jcr.Repository


                  The file jboss-deployment-structure.xml is located in main/resources/META-INF/ within my jcr ejb packaging project.

                   

                  Kind regards,
                  Stefan