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

How do you add a classpath to an EAR file?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a situation where I have several jars that I want to include in an EAR file. The problem that I am running into is that some of the jar files reference properties in their respective manifests. If I execute the classes and have the appropriate jar files in the classpath, they retrieve the information. But when I create the EAR file, when the classes get called they return null for the values as if the manifest is not in the classpath.

How can I create the EAR using Ant where it will add the classpath information to the manifest of the EAR file?
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Do one thing while building ur application.
Create a folder called App-inf/lib.
Under that put all ur jar files and other files

Then make an ear file
It will work

Kunal
 
Randall Stevens
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the EAR build, I currently have the following directory structures;

MyApp
\jar

When I do my Ant build, the build.xml and MyApp.class are in the MyApp directory while all of my jars are in the jar directory.

My ant for creating the ear looks like:


As I am new to ant as well as EAR files, is there a better way to build the EAR so that the jars are in the appropriate directory?
 
Randall Stevens
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anyone out there with an answer? Placing the files in the lib and creating the EAR did not seem to work in this situation.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Randall Stevens:
Is there anyone out there with an answer? Placing the files in the lib and creating the EAR did not seem to work in this situation.



Hi,
the solution is fairly easy and you don't need the APP-INF directory. Last time I checked, that trick was Weblogic specific.

1. Create a MANIFEST.MF file in a META-INF directory.
2. Reference all your third party jar files in your MANIFEST.MF file.
3. Create an new jar file. Call it something like "all_jars.jar"
4. Put all your third party jars in "all_jars.jar".
5. Include the META-INF (with MANIFEST.MF in it) in "all_jars.jar".
6. Include "all_jars.jar" in your ear file.
That's it. This works for instance with the following ear structure:

EAR
- webapp_module.WAR
- ejb_module.JAR
- app_commons.JAR
- all_jars.JAR

As an alternate (but sloppy) solution, you can also put all your third party jar files at the ear root and just add the /META-INF/MANIFEST.MF file as described earlier.

However, I've seen cases where third party tools use

stream = MyClass.class.getResourceAsStream(resource);

instead of

stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);

As a result, the classes in these jar files were able to find and load resources and other classes when their jar file was deployed in the server system classpath, but not when sitting inside an ear file.
In these rare cases, you have no other solution but to patch some of these tools' classes to make them use the currentThread context classloader.
One example of this is the Hibernate ORM framework which is unable to load its xml config file when both the Hibenate jar and the xml file are packaged inside an ear file.

I hope this helps.
Cheers
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic