aspose file tools*
The moose likes Websphere and the fly likes Classloader problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Classloader problem?" Watch "Classloader problem?" New topic
Author

Classloader problem?

Todd Johnson
Ranch Hand

Joined: Sep 03, 2005
Posts: 61
I'm new to web development. I'm working on my first large project. I am using WSAD 5. I have two projects. I have a java project I'll just call "Business" that contains all my business logic (I'm not using any EJBs). I have a web project that I'll call "Web" that contains all my web presentation layer (struts).

I then have an ear file which contains the "web" war file, and the "business" utility project.

My "business" project uses a commercial jar file that I'll just call "commercial". The commerial.jar file is in my web project under WEB-INF/lib. In my "business" project I created a class that extends one of the classes in the "commercial" jar. So something like this...



When I run the code on the server, and a java file in the "web" project tries to instantiate the MyClass object, it fails with


Consider the following code...



The output from this code (if it is part of the web project) would be...



So it can obviously find the CommercialClass when it is instantiated directly from the web project, but when the web project instantiates an object in the business project which extends the CommericalClass it can't find it.

Any ideas?
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

Put the business jar inside the WEB-INF/lib directory of the Web App WAR, or put them both in the top of the EAR.
[ January 24, 2006: Message edited by: Scott Selikoff ]

My Blog: Down Home Country Coding with Scott Selikoff
Todd Johnson
Ranch Hand

Joined: Sep 03, 2005
Posts: 61
Thanks Scott. That's kind of what I figured.

I have another stupid question. Is there an easy way in websphere to specify that commercial.jar should be included directly in the EAR file (instead of including it in the war file)? When I open the ear file in websphere it looks like the only option I have is to include utility project jars (i.e. it wants it to be a project). I don't see anywhere I can just specify a jar file.

Thanks!
Todd
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

These questions are far from stupid, since WebSphere is very tricky handling jars inside of WARs. First off, WebSphere won't build a utility jar to a WAR automatically, but you write an ANT script that will do it for you and include it in the build process.

As far as not putting the utility JAR inside the WAR, you can put as many as you want on the EAR level. You should need to modify the runtime of the WAR (the MANIFEST.MF file) to include that JAR. You can also use resource bundles which is jar files/libraries defined on the server admin level. They have to be setup through the admin console though (or wsadmin scripting).
Todd Johnson
Ranch Hand

Joined: Sep 03, 2005
Posts: 61
Thanks Scott. That would cover the solution where you suggested putting my "business" project into the "web" project's web-inf/lib directory as a jar file. Not being familiar with ANT and having insanely tight deadlines on this project, I'm wondering if the other option you proposed might be easier until I can find some time to learn ANT.

Your other solution was to put the commercial jar file into the top level of the ear file instead of the web-inf/lib directory of my web project. I'm a little confused as how to add a jar file that I don't have source for to the top level of an ear file in websphere. When I open the ear file up in websphere it only gives me the option of including web projects, or utility projects. How does one go about adding a jar file to the top level of the ear file in websphere?

Thanks again for all the help. I really appreciate it.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

Add it as a utility jar first by opening the application.xml deployment descriptor. WSAD will graphically give you the choice, as I believe you've found, to add it as a utility jar. Any all ready compiled jars, like comercial.jar can just be dragged and dropped into the EAR folder. Next right click on the web project and go to runtime dependencies. There you can check which jar files your WAR depends on such as the utility jar or other jars in the ear.
Todd Johnson
Ranch Hand

Joined: Sep 03, 2005
Posts: 61
Excellent! Thanks Scott. I owe you one. I'll give it a shot tomorrow at work.
Todd Johnson
Ranch Hand

Joined: Sep 03, 2005
Posts: 61
Scott,

Adding the commercial.jar to the top level of the ear file worked perfectly.

The funny thing is a couple days ago I was trying to do this from the J2EE perspective by right clicking on the "Utility Jar" folder under the EAR file and trying to import the jar file. For some reason it won't let you do it from there. However from the Java perspective I can right click on the EAR file and import it just fine. I wonder if that is a bug.

Thanks again for the help!
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

Might be, there are a lot of odd things in WSAD/RAD. Keep in mind that a 'utility jar' (in fact any jar/war in the ear) in WSAD really just means that during building it creates a jar file and drops it in the ear. The big advantage in WSAD/RAD is that it internally then picks up in its list of runtime jars, which are available for each ear. The point being, that even building manually, isn't too difficult for just adding a utility jar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classloader problem?