Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

J2EE, weblogic, jar in ear, class loading question.

Options
  • 12-06-2007 9:52pm
    #1
    Closed Accounts Posts: 638 ✭✭✭


    Hey everyone,
    Hoping I could get some help on a piece of java work.

    I have an EAR file called "MyEar".
    I have an EJB Jar file called "MyEjbJar"

    inside MyEjbJar file i have:
    My own custom code, ejb-jar.xml, and weblogic-ejb-jar.xml

    I compile my ejb module with Ant scripts referencing the needed third party jars(hibernate etc) in my lib folder. It all works fine. Since my Jar file needs to reference third party Jars while running, I created the aforementioned EAR file to contain it + the needed libs.

    However, i keep getting a ClassDefNotFoundError for classes in the third party jars. I'm fairly certain that its just not picking up any of the JAR in the EAR file

    MyEar consists of:
    META-INF/MANIFEST.MF
    META-INF/application.xml
    MyEjbJar.jar (contains my custom code which actually uses the third party stuff)
    ThirdPartyJar1.jar
    ThirdPartyJar2.jar
    ThirdPartyJar3.jar


    Can anyone see a mistake im making regards the set up of this? Is my thinking wrong in believing the Third party jars will be accessible by my classes in MyEjbJar.jar.

    heres some things ive tried:
    tried placing all the jars in an APP-INF/lib.
    tried placing all the jars in an APP-INF/lib and the root.
    Just the root.
    Added the jar files into the manifest file classpath property for both the APP-INF/lib way and the root way.

    If its of any relevance, the class inside the MyEjbJar file is a MDB...though i doubt that matters.
    Ive been looking at this problem all damn day and getting no where...

    Thanks for the help.


Comments

  • Registered Users Posts: 995 ✭✭✭cousin_borat


    First of all why are you compiling with ANT? Could you not do this within Weblogic Workshop itself?

    As regards placing your 3rd party Jars. For Hibernate Jars that are being used within Weblogic the 3rd party files are in APP-INF/lib folder.

    This is usually where 3rd party JARs are placed for Weblogic projects.

    I have only worked with Stateless and Stateful Beans but I don't see any difference because it's a MDB.

    ps If you're following one of the Hibernate tutorials for Weblogic let me know the link since I've gone through most of them at one stage or another.


  • Closed Accounts Posts: 638 ✭✭✭theTinker


    First of all why are you compiling with ANT? Could you not do this within Weblogic Workshop itself?

    Its not standard in my job to use workshop. We use ant through eclipse, and for cruise control.
    As regards placing your 3rd party Jars. For Hibernate Jars that are being used within Weblogic the 3rd party files are in APP-INF/lib folder.
    Ye i tried that....doesnt seem to pick them up at all. Its very fustrating, large application logic written but i have no idea if its work because i cant run it as a system...That APP-INF/lib is weblogic specific so i also tried the root and manifest file.
    ps If you're following one of the Hibernate tutorials for Weblogic let me know the link since I've gone through most of them at one stage or another.
    No tutorial, its a fully developed system, just using hibernate in the MDB to record duplicate messages.


  • Registered Users Posts: 1,996 ✭✭✭lynchie


    Placing the jars in the root of the ear, and adding them to the Class-path: xxx section of the manifest.mf in the META-INF directory works. I've used this approach on jboss and websphere all the time.

    You sure its definitely a NoClassDefFound on one of the classes within the ear and not some other dependency of the 3rd party libs.. i.e hibernates dependency on ehcache if u only packaged hibernate.jar


  • Moderators, Entertainment Moderators Posts: 17,993 Mod ✭✭✭✭ixoy


    Certainly sounds right. APP-INF/lib is definitely the place for 3rd party jars in this case (the man at the WebLogic course told me so).

    Is your directory structure within your jar correct? What is it currently? (answering this helps avoid the fact if I turn 180 degrees I have to look at my own WebLogic console/problems...)


  • Closed Accounts Posts: 638 ✭✭✭theTinker


    ixoy wrote:
    Certainly sounds right. APP-INF/lib is definitely the place for 3rd party jars in this case (the man at the WebLogic course told me so).

    Is your directory structure within your jar correct? What is it currently? (answering this helps avoid the fact if I turn 180 degrees I have to look at my own WebLogic console/problems...)

    Replying to this helps me avoid mine a little longer too :)

    Actually I made some progress with this problem today. It was a solution per say.
    I created a new project and set it up like my old one but much simplier. My own created Jar file could access other 3rd party Jars in the Ear file. So i began to copy down my files one at a time...took a LONG time.
    Eventually i was able to trace the problem to a package(one of my own) inside MyEjb.jar(inside MyEar.ear if you remember).
    Moving the files out of a package and into another fixed it...Im not sure why though.

    Old structure was

    com.mycompany.router
    class1 (MDB which talks to class 3)
    class2
    com.mycompany.router.persistance
    class 3 (accesses somefile.xml)
    someHibernateClassMappingfile.xml

    class3 threw the ClassDefNotFoundError upon a static {} initalisation.

    new structure that works now is:
    com.mycompany.stuff
    class1(MDB which talks to class 3)
    class2
    class 3 (accesses somefile.xml)
    someHibernateClassMappingFile.xml


    The imports/references were definitely correct in my class files/xml files so i have no idea why it happens. Obviously a seperate package should work, so im starting to think it might have something to do with the fact that persistance was a sub package of router?
    Is there class loading issues when that happens? I never thought that would of mattered. I would think there would be maybe, if it couldnt find one of my own files/classes, But the fact that it coudlnt find 3rd party jars in the APP-INF/lib folder before i moved my own classes into a different package is quite puzzling. It finds them just fine now.
    I will drag the class3 + mapping file out into a seperate package(on equal level to router) over the next 2 days and report what i find. A lil tight on time at the moment after wasting 2 days!


  • Advertisement
  • Registered Users Posts: 995 ✭✭✭cousin_borat


    There is a weblogic file called weblogic-ejb-jar.xml

    Now I should'nt think you need to create references here. The only time I have had to use this was for JNDI references.

    Just make sure that if you're deploying on Weblogic that this file contains a correct entry for your MDB.

    Good luck BTW


  • Moderators, Entertainment Moderators Posts: 17,993 Mod ✭✭✭✭ixoy


    There is a weblogic file called weblogic-ejb-jar.xml

    Now I should'nt think you need to create references here. The only time I have had to use this was for JNDI references.
    Wouldn't have thought so. It's used primarily for defining functionality around EJBs, not the application itself. Even the weblogic.xml file doesn't seem like a likely culprit.

    The APP-INF/lib folder has plagued me as well at times although not the problem you're having. Out of curiosity, what version are you running?


  • Closed Accounts Posts: 638 ✭✭✭theTinker


    ixoy wrote:
    The APP-INF/lib folder has plagued me as well at times although not the problem you're having. Out of curiosity, what version are you running?

    Weblogic 8.1 SP4.


    Quite the nuisance, As much as I love having a solution. Not understanding the problem is a pain in the arse


  • Registered Users Posts: 995 ✭✭✭cousin_borat


    Oh one other thing. I don't know whether you have investigated using Spring with Weblogic. This allows you to create EJB's by using plain Java Objects and not having to do any of the EJB wiring crap. You can specify the dependencies between objects in an XML configuration file which are then wired together at runtime. Definately made EJB programming alot easier for me.


Advertisement