2 Replies Latest reply: Dec 8, 2005 2:01 PM by 843844 RSS

    How to access a jar file in EAR file?

    843844
      I have a EAR file which contains EJB.jar file and util.jar file. Outside of EAR, I mean in client side, I need to reference util.jar file. How can I access it?

      EAR structure is
      |--+META-INF/
      |--|---application.xml
      |--|---manifest.mf
      |--EJB.jar
      |--|---+MEAT-INF/
      |--|---|--- deployment descriptors...
      |--|---|--- manifest.mf
      |--|--- EJB classes
      |--Util.jar

      Util.jar must be executed in server side. If I just add Util.jar in client program's classpath, when client program is executed, serverside Util.jar is executed? Or what else I should do in the client program to reference server-side Util.jar?
        • 1. Re: How to access a jar file in EAR file?
          843844
          Excellent question. I don't see any client-jar in your EAR file structure. So I am assuming you are writing a separate client application which will talk to the ejbs deployed as part of this EAR. You need to do the following:
          Write another EAR file with the following structure:
          ear:
          META-INF/application.xml
          util.jar
          client.jar
          client.jar should have a META-INF/MANIFEST.MF and that should contain Class-Path:util.jar and value for Main-Class attribute.

          Now deploy this new ear to your application server and execute it using Application Client Container that comes with your app server.

          If you don't want to write another EAR file, then bundle th client.jar in your original EAR file.
          Points to note are:
          you have to repackage util.jar again inside this ear file.
          For portability reason, you should use Class-Path manifest entry in client.jar. Refer to http://java.sun.com/j2ee/verified/packaging.html and J2EE platform spec section #8.2.

          Hope this helps,
          Sahoo
          • 2. Re: How to access a jar file in EAR file?
            843844
            Thanks Sahoo. Your reply helps me to do the job right.