• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

question regarding packaging utility jars

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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?

Thank you very much.
P. Ingle
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the jar file in /WEB-INF/lib
 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?

P.Ingle
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, put the jar file (a single file, not the exploded contents) into WEB-INF/lib.
 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean adding it to the manifest classpath? Per the servlet spec, that's not necessary.
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James, You are right; for some reason I was reading WEB-INF/lib and thinking /lib under the EAR project.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chad McGowan:
James, You are right; for some reason I was reading WEB-INF/lib and thinking /lib under the EAR project.



That's what I figured. In that case, you would have to use the manifest classpath.
 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic