I am developing a ( Struts )web app using WSAD 5.1.2. I have some DTOs in another java project which my Action class needs to use. When I put the jar with DTOs in build-path for web app, the classes get resolved at compile time, but give "NoClassFoundException" at runtime. If I try to import the jar directly into web-INF/classes, it works, but every time I rebuild my project, the imported classes seem to disappear.
I worked around this problem as following: 1. Create another Java Project. Import my jar in there. 2. In my EAR, add this java project as "Project Utility Jar". 3. In my WAR, add dependency to this App level jar.
My questions are, 1. is this the best way of doing this or is there any other better way. 2. how can work with multiple utility jars? 3. I have another jar for sybase driver which I have in the Java project in DTOs. When I export the java project into a jar, the sybase driver jar is not getting jarred along with it - what do I need to do to achieve that?
Originally posted by James Carman: Put the jar file in /WEB-INF/lib
Thanks for your suggetion - when you say put do you mean I need to 'import' the jar under /WEB-INF/lib? I have tried that already - importing the jar file into /WEB-INF/lib
1. I still get java.lang.NoClassDefFoundError for the class in that jar.
2. When I import it into /WEB-INF/lib, it is not lokking like any other jar (like struts.jar) in that folder, instead, it ls looking like whole directory structure that is there in the jar - recreated under /WEB-INF/lib.
3. Do I neet to set anything else up so that it will look there at runtime for those classes?
In WSAD, after you add the jar to WEB-INF/lib, you also need to right-click on the project, select Properties, then select Java JAR dependencies. Check to make sure the jar you need is checked and in the manifest.
I tried following (using WSAD 5.1.2): right-click my web app, select 'properties' select 'Java Build Path' -> 'Add External Jars' - added utility jar under ''Java Build Path' -> 'order and Export' -> selct the newly added jar so that it will be also exported.
It lets me do this only if I have "WebApp/WebContent/WEB-INF/classes" as default folder ( and doesn't allow me to change this default output folder to "WebApp/WebContent/WEB-INF/lib".
I do this with WebApp/WebContent/WEB-INF/classes as default folder. This removes all the compilation errors caused by referencing classes from the utility jar.
At this point, as a result, I see my jar in WebApp/java Resources/Libraries in Web perspective and J2EE perspective, but directly under WebApp in Java perspective.
I did not set java jar dependencies mainly because, it did not pick up my jar as available dependent jar. (Actually it is logical as my WebApp depends on utility jar, not other way round)
And I still have the java.lang.NoClassDefFoundError at runtime.
What am I missing?
Thanks for being so patient and responding. P.Ingle [ May 06, 2005: Message edited by: p Ingle ]
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop