Announcement Announcement Module
Collapse
No announcement yet.
Referencing classes in other projects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Referencing classes in other projects

    I'm trying to get my first Spring web (WebSphere) application up-and-running, so please bear with me

    I had the app functioning when I then realized I had to refactor one of my beans out of the project and into a new non-Spring project. I refactored all of the java code and it compiles fine (I included the new project on the existing project's class-path). However now when I go to start the app up, I get a Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError error. I'm assuming that Spring can't 'see' the class in the other project even though it's linked on the ClassPath.

    So my question is, is it possible to have the app set up this way? I look at the @Import resources option, but that seems to only pertain to configuration files.

    Any suggestions?

    Thanks!

  • #2
    The problem is that classpath references in your IDE are not the same as your deployment package in WebSphere, or any other web container. If those classes are not included in your deployment package, it will fail at run time.

    There are numerous strategies to work through this. The likely simplest (and least maintainable over time) is to simply produce a jar from the non-Spring project and copy that into the WEB-INF/lib of the WAR, and change your classpath reference to that jar, instead of the classes in the other project.

    Comment


    • #3
      Thanks for the quick reply dkar, very helpful. I did think about jar option but I would like to stay clear of it b/c of the maintenance issue you mentioned.

      You mentioned there are numerous strategies for this scenario, would you mind sharing some others that I can look into?

      Comment


      • #4
        Build with Maven. The non-Spring app would produce an artifact that the Spring app depends on.

        Comment


        • #5
          Thanks for the suggestion. I was also able to get this to work by adding project #2 to the Deployment Assembly of Project #1.

          Comment

          Working...
          X