Question

I am working on a legacy application that was written in EJB 2. I want to load it in eclipse and debug it within Eclipse. I know I can build it and deploy it in a local Jboss 5.1 installation and remote debug from Eclipse but the problem with this option is that every time i make a change i have to build and deploy it again.

Now this application is comprised of several folders and is built using ANT. A high level view of the folder structure is shown below:

MyAppServer
    build
        build.xml
    descriptors
        app1.xml
        app2.xml
        app3.xml
        ...
        ...
        app33.xml
    src
        packagefolder1
            com
                xxx
                    xxx
        packagefolder2
            com
                xxx
                    xxx
        packagefolder3
            com
                xxx
                    xxx
    test

There is a descriptor file for each component (a total of about 42 descriptor files). Each of them contain the following definitions

<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd">
<ejb-jar>
   <description>abcd</description>
   <enterprise-beans>
      <session>
         <display-name>xxx Bean</display-name>
         <ejb-name>Xxxx</ejb-name>
         <home>PackageFolder1.xxx.xxx</home>
         <remote>xxx.xxx.xxx</remote>
         <ejb-class>xxx.xxx.xxx</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Bean</transaction-type>
         <resource-ref>
            <res-ref-name>jdbc/myAppDS</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
         </resource-ref>
      </session>
   </enterprise-beans>
</ejb-jar> 

In addition to the descriptor files there are also three files which seem to be generic. application.xml, application-client.xml and web.xml. The contents of these files have the following format

application.xml

<application>
    <display-name>MyAppServer</display-name>
    <module>
        <ejb>app1.jar</ejb>
    </module>
    <module>
        <ejb>app2.jar</ejb>
    </module>
    <module>
        <ejb>app3.jar</ejb>
    </module>
    <module>
        <ejb>app4.jar</ejb>
    </module>
    <module>
        <ejb>app5.jar</ejb>
    </module>
    ....
    ....
    <module>
        <ejb>app42.jar</ejb>
    </module>
</application>

application-client.xml

<application-client>
    <ejb-ref>
        <ejb-ref-name>xxx</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <home>xxx.xxxHome</home>
        <remote>xxxx</remote>
    </ejb-ref>
        <ejb-ref>
        <ejb-ref-name>xxx</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <home>xxx.xxxHome</home>
        <remote>xxxx</remote>
    </ejb-ref>
    ....
    ....
    <ejb-ref>
        <ejb-ref-name>xxx</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <home>xxx.xxxHome</home>
        <remote>xxxx</remote>
    </ejb-ref>
</application-client>

Now when i use the ant build script to build it, i get an EAR file that has the following content

MyAppServer
    config
    META-INF
        MANIFEST.MF
    app1.jar
        META-INF
            ejb-jar.xml
        packageFolder1
            MyClass1.class
    app2.jar
        META-INF
            ejb-jar.xml
        packageFolder2
            MyClass2.class
    app3.jar
        META-INF
            ejb-jar.xml
        packageFolder3
            MyClass3.class
    app4.jar
        META-INF
            ejb-jar.xml
        packageFolder4
            MyClass3.class

So it looks like the ant build sript take each module, builds a jar file, create an ejb-jar.xml and adds it to the EAR file. Each module is packaged as a jar file. I didnt see the application.xml and application-client.xml files in the ear file so im guessing these are used to craete the ear file?

I want to load this application into eclipse and try and debug it. When i create a vanialla EJB 2.1 project in Eclipse, the structure that i get is shown below:

EJB2.1Vanilla
    ejbModule
        META-INF
            ejb-jar.xml
            MANIFEST.MF

What is the best way to load that application so i can run it directly from within eclipse? I think the location of the src folders should not matter, it is how i can re-configure the descriptor files that i am struggling with.

Was it helpful?

Solution

You have a handful of options here:

  • You can complete your ant script with some "deploy" target as in:
  <target name="deploy">
      <copy todir="${YOUR_JBOSS_DEPLOY_DIRECTORY}" file="${THE_EAR_YOU_JUST_GENERATED}"/>
    </target>

And just call it each time you are done with a change. This is the more conservative option as you respect the original packaging (and it should be reasonably fast being JBoss). It looks ugly and hardly integrated with Eclipse, but it is reliable and will work as JBoss auto-deploys the .ear scanning its changes.

  • Another option would be, as you just pointed, creating a vanilla EJB 2 project in Eclipse. Just paste there your /src directory and add it as source directory in your Eclipse project properties tab. Then create a simple EAR project with the Eclipse wizard too and run it into your favorite server. This way you will have it very smoothly integrated with Eclipse, debuggable, modifiable... The weak point of this is you don't respect your original packaging (as good or as bad as it was) and this approach will be hardly usable in your continuous integration (if any)

  • If you have any maven skill, you could mavenize your project by creating a Maven project from some of the EJB archetypes that m2eclipse offers to you. You can copy your /src directory contents right into the src/main/java directory and whatever descriptors it has into the src/main/resources/META-INF. Then you can add it to a mavenized EAR project that will run as easily as option 2 into your Eclipse-controlled server, and this will be 100% compatible with any CI solution you have

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top