aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes How to use jar in EAR in Web project ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to use jar in EAR in Web project ?" Watch "How to use jar in EAR in Web project ?" New topic
Author

How to use jar in EAR in Web project ?

Mikhael Jenings
Greenhorn

Joined: Apr 14, 2009
Posts: 25
I need to solve this case.

I have a jar file that needs to be put in the EAR project and needs to be accessed in the Web project in a jsp.
How to do this ?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29241
    
139

You place it in the EAR file and have the Web project point to it there. Are you encountering a problem with this? If you share the problem, you are likely to get a more useful answer.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Classloading and application packaging can be tricky business in J2EE.

I wrote a little article on classloading and packaging. Half-way down this page there's a section called 'How to Package our J2EE applications.' You might find it interesting.
Application Packaging and J2EE Classloading

As Jeanne mentioned, a good option is to have the jar in the EAR, and then have the web module reference that ear. Different development and packaging tools have different means of doing that.

Remember though, if that jar in the ear is updated, every war or ejb module must be updated at the same time to use that new jar file. That's not a big deal if you only have one web module. It might be problematic if you have many. Another option is to put a copy of the jar file in each web module's lib folder. The benefit is that this eliminates a common dependency between war files in the ear. The drawback is obvious - duplication and management.

Good luck!

-Cameron McKenzie

Mikhael Jenings
Greenhorn

Joined: Apr 14, 2009
Posts: 25
Thanks Jeanne & Cameron,

I put the jar in the ear, and put in a "Class-Path" entry in the manifest file of the web module specifying the jar file.

Cameron, the article was a good read. Covered stuff that I came across and ones that I never thought about.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Always happy to help the 'greenhorns!'

-Cameron McKenzie
Mikhael Jenings
Greenhorn

Joined: Apr 14, 2009
Posts: 25
Going through the article and the downside of having a jar file in ear used my multiple web modules, I had a question.

Say, all the multiple web-modules are not able to upgrade at the same time, then having the (common) jar file versioned could help the cause of both the upgrading and yet-to-upgrade apps. Would it or would it not ?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

So, you've got an EAR that has a web module for the accounting, human resources (hr) and corporate websites. That's three war files in a common EAR.

If you put a common jar file in the EAR, all three can point to one JAR file. That's good. But, if you upgrade that EAR to a newer version, EVERY war file will need to upgrade at the same time, right?

So, given three web applications, have you ever seen three separate projects capable of being all upgraded at the same time, on the same schedule? Yeah, me neither.

If you put the common jar file in each web lib folder, any one module could upgrade independent of the others.

It's a pretty contrived scenario. Who knows, perhaps the accounting, hr and corporate websites should be in totally separate EAR files. Heh...That's another discussion.

But yes, your point is well taken. It's all about balance, and knowing your problem domain.

>>then having the (common) jar file versioned

I guess I don't know where you're going with this. You won't be allowed to have two jar files, with the same name but different version numbers in the lib folder. Well, technically you can, but if the two JARs have classes with the same name, how will you, or the JDK, know which class to load? new MyClass() doesn't specify a version number when you invoke it in your code. How would the JVM know if it should pick up v1.0 or v1.1?

It's not actually that uncommon of a problem. You often see people withe MethodNotFoundExceptions because they have multiple versions of the same class on their classpath, and the JVM is picking up a version that the program wasn't expecting.

Landmines....All sorts of landmines. Be careful!

-Cameron McKenzie
Mikhael Jenings
Greenhorn

Joined: Apr 14, 2009
Posts: 25
Yes, hands on with that one :-)

Need help on this one, I put in a jar in the ear and put in the entry in manifest file of web module as this,



The jar file is in the lib directory of the ear as such,

How should I specify the Class-Path entry in the manifest file ? (as shown above or some other correct way ?)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use jar in EAR in Web project ?
 
Similar Threads
question regarding packaging utility jars
Access Project Utility Jar which is outside of WebContent\WEB-INF\lib from web proj packaged as EAR
jars within jars
Deploying My project in Jboss server
How to set conflicting MANIFEST jar name