problem in importing jars in struts project


Web tier: servlets, JSP, Web frameworks: problem in importing jars in struts project

  1. problem in importing jars in struts project (2 messages)


    I am working on (my first) struts web app using WSAD. I have created a bunch of java files (DAOs and DTOs)in one project and want to be able to use those in my struts web project so that my Action classes could instantiate DTOs and call my DAO methods.

    For that, I want to export my java classes in a jar and the import them in my struts project where I can instatiate those classes from Action class.
    Sounds fairly simple, doesn't it?

    I tried exactly that. The import statements in my Action class are getting resolved hence no compilation errors. But at runtime, it is not able to find my java classes.
    It gives me servlet Error saying

    [4/29/05 15:18:54:188 CDT] 53558d49 WebGroup E SRVE0026E: [Servlet Error]-[com/..../dto/myDTO]: java.lang.NoClassDefFoundError: com/..../dto/myDTO

    Am I doing it the wrong way?
  2. problem in importing jars in struts project[ Go to top ]

    Sounds like a class loader issue. If you're packaging your Struts app as a multi-tier deployment, make sure that the jar containing the DTOs is at or higher than the highest packaged level that utilizes them. (e.g. if your struts app is an .ear file that contains a .war file that contains a .jar file and the Action classes are at the .war level, make sure you add your .jar file with the DTOs to that .war or the .ear. That way the classloader will be able to find them at run time)
  3. I still have the same problem.
    I am using WSAD. Is there any web resource that gives step-by-step instructions what I ought to be doing?

    I am taking following steps:
    1. from java project where I have my DTOs, Choose packages to be exported, right-click and launch export wizard.
    2. selct 'Export to Jar", and unselect .classpath, .project, Manifest.INF - so that they are not included in jar
    3. hit finish - which creates the jar

    Now from Struts Web App Project:
    1. Right-click to launch import wizard
    2. select the jar to be imported - choose destination folder to be WebContent\Web-INF\lib
    3. At this point I see my classes in form of any regular package under lib ( and not as any other jar with a symbol of glass jar besides it)

    Now start the test-server (in-built with WSAD), launch web app. It shows first form ok, but when it comes to executing that Action class where I instantiate DTOs from my jar, it fails and gives me "NoClassDefFoundError"

    By the way, if I import these in WebContent\Web-INF
    classes, it works fine, but as soon as I rebuild by project, the imported packages and hence classes just disappear.

    I am missing some step or doing it wrong, any clue?

             And I thought it will be easy.