Title: RE: [JBoss-user] JBOSS INTEREST EXAMPLE

Here is a summary of ejb-jar files, war files and ear files and how to build them with ant.

Before we start it is recommended to have a standard directory structure set up, this can be as simple or as complex as you want but for most applications the following would suffice.

myproject\
        build\ (Contains your build script)
        classes\ (All the compiled class files)
        dist\ (Directory for the jar, war and ear files you create)
        doc\ (Any documentation you write)
                api\ (The api documentation for your classes
        lib\ (Any third party libraries you use)
        sql\ (The scripts to generate your database)
        src\ (All your java source files and descriptors)
        web\ (One or more web applications)
                mywebapp\ (A web application)

For the ejbs also use a standard naming structure the one I use is as follows, this makes automating the build much easier.

My.java (The remote interface)
MyHome.java (The home interface)
MyEJB.java (The ejb implementation file)

1. Compiling the source code using ant

<project basedir=".." default="compile" name="build">

  <!-- Set to false to turn off debug information in the generated class files -->
  <property name="debug" value="true"/>

  <!-- List all of the library files you need to compile your application -->
  <path id="base.classpath">
    <pathelement location="lib/j2ee.jar"/>
    <pathelement location="lib/jaas.jar"/>
    <pathelement location="lib/jbosssx-client.jar"/>
    <pathelement location="classes"/>
  </path>
  <property name="classpath" refid="base.classpath"/>

  <!-- Compile all packages below the src dir into the classes dir -->
  <target name="compile">
    <javac classpathref=""base.classpath"" debug="${debug}" destdir="classes" srcdir="src"/>
  </target>

</project>

2. Ejb-jar files

An ejb jar file contains one of more enterprise java beans (session, entity on message driven beans).

The structure of this jar file is as follows (asumes your class files are in the com.demo.myejb java package.

com\
        demo\
                myejb\
                        My.class
                        MyEJB.class
                        MyHome.class
META-INF\
        ejb-jar.xml (The sun J2EE deployment descriptor)
        jboss.xml (The jboss deployment descriptor)
        jaws.xml (The jboss deployment descriptor that describes how to map container managed entity beans to the database)

If these classes rely on any classes internally that are not part of the standard jdk, the system classpath or the jboss lib/ext directory you must also include those classes in this jar file.

You can have more than one ejb in the same jar file all you need to do is add the classes for all of those ejb's in the jar file and add one entry in the deployment descriptors for each ejb.

I'm not going to go into detail here about the descriptor files but you can find some good documentation on the following sites; ejb-jar.xml (http://www.jboss.org/documentation/HTML/ch01s12.html), jboss.xml (http://www.jboss.org/documentation/HTML/ch06s02.html), jaws.xml (http://www.jboss.org/documentation/HTML/ch05.html).

So how do we take our deployment descriptors and package them in a jar file?

Again we should have a directory structure for the deployment descriptors, there are several ways to do this but the easiest for now is to create a META-INF sub directory under the package directory for the ejb source so in this example the path would be src\com\demo\myejb\META-INF. To build the jar file we can now add the following task which adds the class files and the meta inf files to a new jar file.


  <target name="myejb" depends="compile">
    <jar jarfile="dist/my.jar">
<!-- include any class files -->
        <fileset dir="classes">
          <include name="com/demo/myejb/*.class" />
      </fileset>
<!-- include my deployment descriptors -->
        <fileset dir="src/com/demo/myejb">
          <include name="META-INF/*.xml" />
      </fileset>
    </jar>
  </target>

In the classes fileset you can add an extra includes tag to include any utility classes required.

If you are not going to build an ear file you can just pop this in the deploy directory and away you go. If you are using an ear file the only file you need to deploy is the ear file.

3. Web applications

The required structure of an war file is as follows, at the same level as WEB-INF you must put all of you jsp, image and html files that you wish to be served from the web server. All a war file is is a jar file with the .war extension and the WEB-INF folder in it.

WEB-INF\
        web.xml (The J2EE deployment descriptor)
        jboss-web.xml (The jboss deployment descriptor)
        classes\ (Any class files or servlet class files in package structure)
        lib\ (Any thrid party libraries or classes wrapped as library jar files)

You must put the class files for the home and remote interafaces of any ejb's you use in the classes or lib directory (wrapped in a jar).

This whole directory structure should be put under one of the web apps in your standard development tree and then all we have to do is jar it all up, the following ant command can be used to build the war file.

  <target name="war">
    <copy todir="web/mywebapp/classes">
      <fileset dir="classes">
        <include name="**/*.class" />
        <exclude name="**/*EJB.class />
      </fileset>
    </copy>
    <jar basedir="web/mywebapp" jarfile="dist/my.war"/>
  </target>

If you are not using any ejb's you can just drop this in the deploy directory and away you go.

4. The ear file

The ear file just contains all the ejb-jar files and war files that make up your application and the path the web application is deployed at. It is just a jar file with the .ear extension. The directory structure is as follows.

my.jar
my.war
META-INF\
        application.xml

The deployment descriptor for this app would be as follows in the file application.xml.

<application>
        <display-name>My Application</display-name>

        <module>
                <web>
                        <web-uri>my.war</web-uri>
                        <context-root>/my</context-root>
                </web>
        </module>

        <module>
                <ejb>my.jar</ejb>
        </module>
</application>

Under the src directory create a META-INF diretcory with the application.xml file and then we can deploy using the following task in ant.


  <target name="ear" depends="war,myejb">
    <jar jarfile="dist/lib/my.ear">
          <fileset dir="dist/lib">
            <include name="my.jar"/>
            <include name="my.war"/>
          </fileset>
          <fileset dir="src" includes="META-INF/application.xml"/>
        </jar>
  </target>

Then to deploy copy the ear file and the ear file alone to the deploy directory.

I hope this has helped to clear up any confusion.

Paul

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of A.L.
Sent: 07 August 2001 15:20
To: [EMAIL PROTECTED]
Subject: RE: [JBoss-user] JBOSS INTEREST EXAMPLE


It would sure be of interest to me. 

Thanks Again,
 -Amos



--- Martin Welch <[EMAIL PROTECTED]> wrote:
> Amos,
>
> Erk. Hands up -- I didn't use EAR, WARs etc. I've
> done everything by hand --
> a batch file to create the jars and a manual copy of
> all the necessary
> files.
>
> My next step is to create a simple example of my own
> and use Ant (which I
> don't understand at all yet) to create there EARs
> and WARs (which I also
> don't understand).
>
> If you wish I'll document what I did if that helps.
> Would this be of
> interest to others?
>
> Martin
> -----Original Message-----
> From: A.L. [mailto:[EMAIL PROTECTED]]
> Sent: 03 August 2001 16:36
> To: [EMAIL PROTECTED]
> Subject: RE: [JBoss-user] JBOSS INTEREST EXAMPLE
>
>
> Martin,
>    I know I'm starting to be a real pain, and this
> is
> quite frustrating, but it still is not working.  I
> have deployed the files and made sure that
> InterestHome was appearing in the WebInf directory
> in
> the Interest Jar WAR  and EAR files.
> I have an idea though.
>   Could you send me your EAR file.  Maybe I can then
> deploy it with yours, and see what is diferrent.
>
> One other simple question.  Which is necessary to
> deploy the whole application.  The Jar Ear or the
> WAR
> file.  Or do all of them ned to be in the deploy
> folder.  Currently I have all of them.  It is my
> understanding that I only need to have the ear fiel
> though.
>
> Thanks Again
> -Amos
>
>
>
> --- Martin Welch <[EMAIL PROTECTED]> wrote:
> > Sorry for the delay in my reply -- real work got
> in
> > the way again!
> >
> > Just double check that you've also got
> > Interest.class and InterestHome.class
> > in your
> >
>
C:\work\example\examples\build-examples\interest\WEB-INF\classes\org\jboss\d
> > ocs\interest directory.
> >
> > This is why I got the same error as you.
> >
> > HTH,
> >
> > Martin
> >
> > -----Original Message-----
> > From: A.L. [mailto:[EMAIL PROTECTED]]
> > Sent: 01 August 2001 16:13
> > To: [EMAIL PROTECTED]
> > Subject: RE: [JBoss-user] JBOSS INTEREST EXAMPLE
> >
> >
> > The immediate naswer to you question is:
> > The interestservlet.class file was created in:
> >
>
C:\work\example\examples\build-examples\interest\WEB-INF\classes\org\jboss\d
> > ocs\interest
> >
> > Here is some more background info...
> >
> > When I downloaded the files for the interest
> example
> > I
> > put them all into the following directory:
> >
> > C:\work\example\examples\org\jboss\docs\interest
> >
> > After running the ant compile command from the
> > directory
> > C:\work\example\examples\build
> >
> > A new Directory was created with the follwoing
> > structure
> > C:\work\example\examples\build-examples
> >
> > The interestservlet.class file was created in:
> >
>
C:\work\example\examples\build-examples\interest\WEB-INF\classes\org\jboss\d
> > ocs\interest
> >
> > Nevertheless,  After running all the ant commands
> > defined in the build.xml file, interest.JAR,
> > interest.WAR, and interest.EAR all were placed in
> > the
> > JBoss deploy file.  I assume they all have the
> > compressed the same directory structure I have
> > described above.
> >
> > I hope that this is correct, if not I'm an idiot
> for
> > having messed this up.
> >
> >
> > Thanks again Martin
> >
> > --- Martin Welch <[EMAIL PROTECTED]> wrote:
> > > Where is your InterestServlet.class file?
> > >
> > > -----Original Message-----
> > > From: A.L. [mailto:[EMAIL PROTECTED]]
> > > Sent: 31 July 2001 17:20
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: [JBoss-user] JBOSS INTEREST EXAMPLE
> > >
> > >
> > > I have finally tried to restart the whole
> process
> > to
> > > get the Interest Servlet to work. now I am
> getting
> > > the
> > > following error when I try to calculate:
> > >  Error: 500
> > > Location: /interest/InterestServlet
> > > Internal Servlet Error:
> > >
> > > java.lang.NoClassDefFoundError:
> > > org/jboss/docs/interest/Interest
> > >   at java.lang.Class.newInstance0(Native Method)
> > >   at java.lang.Class.newInstance(Unknown Source)
> > >         .
> > >         .
> > >         .
> > >
> > > I have a couple of questions.  The
> interestClient
> > > class is running fine, and has the following
> line:
> > >  Object ref  =
> > > jndiContext.lookup("interest/Interest");
> > >
> > > I have put the same line in the InterestServlet
> > > Class.
> > >  Yet i am still getting an errors.  Any ideas
> why?
> > >
> > > Also when I try to deploy the servlet Class with
> > the
> > > line       Object ref  =
> > >
> jndiContext.lookup("java:comp/env/ejb/Interest");
> > > it also doesn't work.
> > >
> > > I meanwhile have jboss.xml,  jboss-web.xml, and
> > > web.xml
> > > .  These all seem to be configured properly.  I
> > > would
> > > assume they would be anyways since I downloaded
> > them
> > > from the Jboss web site.
> > >
> > >
> > > Finally.  Which file must go into the
> > Jboss/deploy/
> > > directory for the servlet to run.  Interest.EAR,
> > > Interest.WAR, or Interest.JAR.  Do all of them
> go
> > > into
> > > the deploy directory?
> > >
> > >
> __________________________________________________
> > > Do You Yahoo!?
> > > Make international calls for as low as
> $.04/minute
> > > with Yahoo! Messenger
> > > http://phonecard.yahoo.com/
> > >
> > > _______________________________________________
> > > JBoss-user mailing list
> > > [EMAIL PROTECTED]
> > >
> >
>
http://lists.sourceforge.net/lists/listinfo/jboss-user
> > >
> >
> >
>
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to