14 Replies Latest reply on Jun 29, 2009 12:53 PM by adrianoats

    Is this JBoss or an iBatis issue?  Classpath issues...

    asack

      Alright, I'm using 404CR2 with EAR isolation on. I have the following EAR:

      my.ear
      META-INF/application.xml
      my.jar
      lib/ibatis-common-2.jar
      lib/ibatis-sqlmap-2.jar
      lib/ibatis-dao-2.jar

      my.jar
      META-INF/MANIFEST.MF
      com/blah/blah/conifg/sql-map-config.xml

      The my.jar MANIFEST.MF file has Class-Path entries for lib/ibatis-*.jar entries, etc. The my.jar is full of EJB3 beans.

      When I deploy the EAR with 404CR2, iBatis claims it can't find com/blah/blah/config/sql-map-config.xml using getReaderResource() which is suppose to look for the file within the current runninng thread's classpath. Looking at the source, it uses getClass().getLoader() to load the file as well as its own default classloader (Thread.currentThread().getCointextClassLoader()). Why isn't the mu.jar file in the current classpath during runtime?

      If I grab the parent classloader, its visible but now another class in ane xternal JAR file shared across EARs is no longer visible during iBatis configuration (there is a typeHandler class that is used in a common library).

      It seems to me that no matter what, my.jar should be visible at runtime without playing with the context classloader. Help!

        • 1. Re: Is this JBoss or an iBatis issue?  Classpath issues...
          asack

          Just to add, the exception I'm getting is:

          java.io.IOException: Could not find resource "com/blah/blah/sqlmapConfig.xml" etc. which is definitely in the my.jar module.

          • 2. Re: Is this JBoss or an iBatis issue?  Classpath issues...
            asack

             

            "asack" wrote:
            Just to add, the exception I'm getting is:

            java.io.IOException: Could not find resource "com/blah/blah/sqlmapConfig.xml" etc. which is definitely in the my.jar module.


            Well it seems I can load if I set the current Context ClassLoader to myClass.getClass().getClassLoader(). I obviously do not understand JBoss class loading strategy as well as I thought. Why do I have do this since I should have classloading scope within my own EAR? (I tried 403SP1 and 404RC2 with the same results). Also if I do this then if iBatis needs anything from a common library (like a type callback handler), its no longer visible unless I include it within the EAR - I *thought* I could a bunch of EARs sharing one library resource that provides interfaces and objects ocmmon to all of them.

            • 3. Re: Is this JBoss or an iBatis issue?  Classpath issues...
              asack

              Has anyone ever used iBatis from within an EAR with EAR isolation on? If so, what was your package layout and where were are your resource files? Any advice would be much apprecaited. I'm going nuts with this one.

              • 4. Re: Is this JBoss or an iBatis issue?  Classpath issues...

                Sorry to re-open such an old thread but, as my colleague above sad so perfectly, I'm also going nuts with this one.

                Same problem: Ibatis, configuration files, mysql connector all inside a jar file.

                When running my app, whenever I try to get a Reader from the resource(getResourceAsReader(packageA/packageB/dao.xml)) an IO.Exception is thrown (could not find resource at: packageA/packageB/dao.xml).

                The xml file is inside the jar and I dont have a clue what I'm missing here.

                Can anyone please give me some directions?

                Sir asack, did you solve that? What did you do?

                Thanks in advance. Any help would be really darn good.

                Thanks and sorry about my lousy english.

                • 5. Re: Is this JBoss or an iBatis issue?  Classpath issues...
                  jaikiran

                   

                  whenever I try to get a Reader from the resource(getResourceAsReader(packageA/packageB/dao.xml)) an IO.Exception is thrown (could not find resource at: packageA/packageB/dao.xml).


                  Please post your code as well as the exception stacktrace.

                  While posting logs or xml content or code, please remember to wrap it in a code block by using the Code button in the message editor window. Please use the Preview button to ensure that your post is correctly formatted.

                  • 6. Re: Is this JBoss or an iBatis issue?  Classpath issues...

                    Hey Jaikiran, thanks a lot for your support...

                    Here is the code......


                    
                    DaoManager gerenteDB;
                    
                    private static void carregarBD() {
                    
                     try {
                    
                    
                    
                     gerenteBD = DaoManagerBuilder.buildDaoManager(Resources
                     .getResourceAsReader(resource), properties);
                     } catch (DaoException e) {
                     e.printStackTrace();
                     } catch (IOException e) {
                     e.printStackTrace();
                     }
                     }


                    And here is the stack trace

                    14:12:00,280 ERROR [STDERR] java.io.IOException: Could not find resource sped/contabil/entidade/dao.xml
                    14:12:00,280 ERROR [STDERR] at com.ibatis.common.resources.Resources.getResourceAsStream(Resources.java:101)
                    14:12:00,280 ERROR [STDERR] at com.ibatis.common.resources.Resources.getResourceAsStream(Resources.java:86)
                    14:12:00,280 ERROR [STDERR] at com.ibatis.common.resources.Resources.getResourceAsReader(Resources.java:150)
                    14:12:00,280 ERROR [STDERR] at sped.contabil.entidade.ConexaoBD.carregarBD(ConexaoBD.java:186)


                    I found the following link https://jira.jboss.org/jira/browse/JBAS-3086

                    On that link, it seems that is a workaround is explained but... I didn't quite get it.

                    Is my doubt understandable now? If not, please ask for any detail you'd like because, I gotta admit, I have no further ideas for this problem.

                    Thanks a lot.

                    • 7. Re: Is this JBoss or an iBatis issue?  Classpath issues...

                      In time,

                      resource is a String with the content: sped/contabil/entidade/dao.xml


                      Thanks

                      • 8. Re: Is this JBoss or an iBatis issue?  Classpath issues...
                        jaikiran

                        Which exact version of JBoss AS, Java and iBatis do you use?

                        • 9. Re: Is this JBoss or an iBatis issue?  Classpath issues...

                          Thanks again, my friend.... here is the info you've requested

                          Ibatis:

                          Implementation-Version: 2.1.7 build# 597

                          Jdk: jdk1.5.0_15

                          Jboss Version: 4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221140)


                          Any ideas?

                          Thanks.



                          • 10. Re: Is this JBoss or an iBatis issue?  Classpath issues...
                            jaikiran

                            Try this change in your code:

                            gerenteBD = DaoManagerBuilder.buildDaoManager(Resources
                             .getResourceAsReader(this.getClass().getClassLoader(), resource), properties);
                            


                            • 11. Re: Is this JBoss or an iBatis issue?  Classpath issues...

                              Hmmm thanks....

                              At first try, it didn't work.....

                              Thanks a lot for your support.

                              • 12. Re: Is this JBoss or an iBatis issue?  Classpath issues...

                                Unfortunately,

                                That didn't work indeed. I´ve tested a lot of variations too with no sucess....

                                Thanks a lot for your support.

                                • 13. Re: Is this JBoss or an iBatis issue?  Classpath issues...
                                  jaikiran

                                  It's mainly related to which classloader iBatis ends up using. I guess it's using the wrong classloader. I thought passing the classloader would fix the issue, but as you mention it doesn't. It probably might be a good idea to open a forum thread in iBatis forums.

                                  • 14. Re: Is this JBoss or an iBatis issue?  Classpath issues...

                                    I see, thanks for the help and explanation...

                                    Could you, please, tell me a little more about the classloaders...

                                    I got it when you said that Ibatis ends using the wrong one.... what I didnt get was what are it's options?

                                    Is there more than one classloader in a web app? why is that?

                                    Thanks.