• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use jar in EAR in Web project ?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Always happy to help the 'greenhorns!'

-Cameron McKenzie
 
Mikhael Jenings
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?)
reply
    Bookmark Topic Watch Topic
  • New Topic