Results 1 to 13 of 13
  1. #1
    liorchaga is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default class instantiation in referenced project causes ClassNotFoundException

    I have a web project with an abstract class called AbstractModel.
    This abstract class have many derived implementations. So far everything is good and working well.
    I'd like to take the implementations outside of the web project, for they are not part of the actual project.

    So I've created a simple java project, and copied one of the implemented classes (and excluded it from the original web project).
    In the new project, called clients, I've made a project reference to the web project.

    In the web project, I've added to the classpath of the web server (tomcat) the bin folder of the Clients project, so when the application could instantiate the derived class.
    When I invoke the derived class instantiation, I get a ClassNotFoundException on the AbstractModel class.
    I tried many things like adding classpath reference in the clients project to the bin folder of the web project. Nothing helped.

    I see that the ClassLoader is looking for the AbstractModel in the bin folder of the clients project.

    What am I doing wrong?

    Thanks,
    Lior

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default

    Create a jar from your subproject and add it into your web project.
    That way (depending on IDE possibly) when you deply it'll deploy the jar as well.

  3. #3
    liorchaga is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    Thanks, but that's a less preferable option for me.
    The idea is that the project team is divided in two, one team is working on the project functionality, and the other is working on new implementations of models. So both sub projects are live and kicking. So I'd rather not using a jar.

  4. #4
    liorchaga is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    It appears that I've missed something, and the web app can't even find the derived class in the clients project...
    I think I have a lead - the WebappClassLoader has a repositories list to look in for classes. This list contain only the default classes folder under the web-app. Is there a way to add a location?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default

    "Not use a jar"?
    Jars are pretty fundamental to deployment, especially when dividing up work, if only to help in the versioning of things.

    Anyway, whatever method yu choose the classes need to be accessible from the webapp, not tomcat itself. Generally this would be the lib directory with jars, or the classes directory.

  6. #6
    liorchaga is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    For deployment purposes I totally agree that a jar would suffice. But for ongoing development, when every day implementations in the client project are added / modified, I'd rather avoid the fuss of jars.

    Anyway, what you are saying about being accessible to the webapp, this is quite surprising to me. It doesn't seems right that I wouldn't be able to supply external resources to the application through the class path, and I even use it:
    1. The properties file used for configuration is added to the classpath of the tomcat, and is being use by the application.
    2. In another project we developed for a client of ours, which is using web seal, the jars for security resides in an external folder, and can be updated by the client. We did however compile our project against stubs of these jars, but we omitted them from the deployment.


    Anyway, one of my colleagues suspects that because we have our own implementation of class loader, things get out of the usual course. We use a class loader that monitors the class files and reloads them if they are changed (our application supports modifying and recompiling of model implementations).
    So we might have broken the pattern of class loading. We'll check it out and on the mean time we'll use jars.

    Thanks for you help.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default

    If you're working on them as separate (but related) projects then jars are the way forward...it's been the case on any project I've been on. If not then they are not separate, and are presumably then part and parcel of the project...so may as well be in the same change control project.

    A webapp should be standalone. Webapp A may require a different set of jars (and versions) than webapp B. Consequently the generally accepted best practice is to deploy each app as a separate entity complete with dependencies. You run the risk otherwise of dependency problems.

  8. #8
    liorchaga is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    I take your advice on the jar, but I would like to argue on whether a webapp should be always independent or use external resources. Maybe a clarification of what the application is doing would assist me explain:

    We have an application which can execute financial models. Each model derives from an abstract model which receives an input map and returns an output map. Whatever happens inside a model is its own business, and except for using supported data types and calling built-in functions, it can do whatever it wants (we have an xml-based syntax for writing models which imposes the restrictions of types and build-in functions).

    So that basically leads us to divide our code to the webapp, which we consider to be the product for which we would release new versions, and the models implementations, which, for the moment, are written by another team in the company, but on the future it's something our clients would be able to do on themselves.
    So now, if I'm releasing a new version of the application, I don't see a need to include the model implementations as part of the deployed WAR. Actually, I might not even have the implementations because they were written by my client on a remote server under his responsibility. That's why I'd like the model repository (including the classes themselves) to be separated.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default

    And the models are written as Java?
    So essentially you have a form of plugin model system, done as a webapp?

  10. #10
    liorchaga is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    The models are written in XML as a script. Then they are parsed and compiled into java classes.

    The application is among other thing a form of plugin model system. But once you've defined these models, you can create "products" based on these models (i.e. instances of models with specific input), make an analysis of these models, produce reports based on their output etc.
    In sum, the application provides many features that use these models, but the models are simply a smart repository that represents logic.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default

    Ahhh!
    I see now...

    So the bit that does the parsing is what generates this other code that you then want included in the webapp, which is why you have your own class loader.

    Sorry for sounding a bit "this is the way" up there, but most of the people we get asking questions on here really don't understand the fundamentals...I do have a tendency to default to the "are you sure?" approach.
    :)

    Have you tried over at the Sun forums? I could hazard a shot at this, but it's a Monday and the youngest was a pain last night...and I have two projects to manage this afternoon. Or you could try here up in the Advanced section possibly (gets slightly more traffic) and post a link to this thread and vice versa, just so anyone else doesn't end up repeating what's already been said.

  12. #12
    liorchaga is offline Member
    Join Date
    May 2010
    Posts
    7
    Rep Power
    0

    Default

    That's OK, I'm not sure I fall in the "understand the fundamentals" category :)

    I would try the forums you suggested.

    Thanks a lot for your attention!!! And sorry for withholding the information (didn't want to weary people with too much data).

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default

    It's difficult to strike the right balance between the right amount of info and too much. We have people dumping pages of code on here and asking why i doesn't work...which always makes me chuckle. Then we have others who write what amounts to "my code doesn't work", with no code, no exception text, nothing. And then getting that information is like extracting blood from a stone...

    Considering there was a weekend in the way you've been quick on the replies.

Similar Threads

  1. XML instantiation by xpath
    By freaksta in forum XML
    Replies: 1
    Last Post: 11-22-2009, 11:25 AM
  2. Instantiation order
    By Jeremy720 in forum New To Java
    Replies: 3
    Last Post: 07-17-2009, 04:19 PM
  3. instantiation
    By Camden in forum New To Java
    Replies: 1
    Last Post: 03-02-2008, 05:44 PM
  4. Instantiation
    By kavithas in forum New To Java
    Replies: 2
    Last Post: 12-05-2007, 05:56 PM
  5. object instantiation and arrayList
    By lockmac in forum New To Java
    Replies: 5
    Last Post: 08-09-2007, 07:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •