aspose file tools*
The moose likes Websphere and the fly likes question regarding packaging  utility jars Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "question regarding packaging  utility jars " Watch "question regarding packaging  utility jars " New topic
Author

question regarding packaging utility jars

P. Ingle
Ranch Hand

Joined: Apr 25, 2005
Posts: 45
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


Thanks,<br />P.Ingle
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Put the jar file in /WEB-INF/lib


James Carman, President<br />Carman Consulting, Inc.
P. Ingle
Ranch Hand

Joined: Apr 25, 2005
Posts: 45
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

Joined: Feb 20, 2001
Posts: 580
No, put the jar file (a single file, not the exploded contents) into WEB-INF/lib.
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
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

Joined: Feb 20, 2001
Posts: 580
Do you mean adding it to the manifest classpath? Per the servlet spec, that's not necessary.
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
James, You are right; for some reason I was reading WEB-INF/lib and thinking /lib under the EAR project.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
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

Joined: Apr 25, 2005
Posts: 45
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: question regarding packaging utility jars