seam-gen and multiple projects part two

Home/Java/JBoss/Seam/seam-gen and multiple projects part two

This is a follow-up from my post two days ago “seam-gen and multiple projects“.

After some feedback from “atao” in this thread on the JBoss Seam forum, I have taken a different approach to the problem, and have enhanced seam-gen to generate targets within the generated project’s ant build script, which in turn call the related seam-gen tasks. This is more elegant for two reasons. Firstly, the projects are independent and don’t rely on special configs kept outside of the project. Secondly, you can run those tasks from within your IDE (Eclipse for me) while doing development. You don’t have to fire up a command prompt, navigate to your seam installation, and run the seam-gen commands there. All in all a much better solution. Thank you very much “atao” for the better approach.

The changes made to the seam-gen related files are slightly more extensive than the previous approach, but well worth it.

First: in $SEAM_HOME/seam-gen/build-scripts you need to change build.properties to contain this:

jboss.home=@jbossHome@
seamgen.home=@seamGenHome@

Second: in $SEAM_HOME/seam-gen/build-scripts you need to add the following block at the bottom of the build file (just before the tag):


<target name="update-project" description="Update project dependencies">
<ant antfile="${seamgen.home}/build.xml" target="update-project" dir="${seamgen.home}"></ant></target>

<property file="seamgen.properties"></property> <target name="new-action" description="Create a new action">
<ant antfile="${seamgen.home}/build.xml" target="new-action" dir="${seamgen.home}"></ant></target>
<property file="seamgen.properties"></property> <target name="new-form" description="Create a new form action">
<ant antfile="${seamgen.home}/build.xml" target="new-form" dir="${seamgen.home}"></ant></target>
<property file="seamgen.properties"></property> <target name="new-conversation" description="Create a new conversation">
<ant antfile="${seamgen.home}/build.xml" target="new-conversation" dir="${seamgen.home}"></ant></target>
<property file="seamgen.properties"></property> <target name="new-entity" description="Create a new entity">
<ant antfile="${seamgen.home}/build.xml" target="new-entity" dir="${seamgen.home}"></ant></target>
<property file="seamgen.properties"></property> <target name="generate-entities" description="Reverse engineer entities from the database">
<ant antfile="${seamgen.home}/build.xml" target="generate-entities" dir="${seamgen.home}"></ant></target>
<property file="seamgen.properties"></property>

Finally, in $SEAM_HOME/seam-gen you need to make a few edits to build.xml:

in the definition of the “project” filterset, within the “init-properties” target, you need to add the following filter (I put mine right after line 97 of revision 1.90):

<filter token="seamGenHome" value="${basedir}">
</filter>

Then, in the “file-copy” target, you need to add the following task call (I put mine on line 632 of revision 1.90):

<copy file="build.properties" tofile="${project.home}/seamgen.properties">
</copy>

If you want to just download the enhanced files here they are (based on the current head as of today):

$SEAM_HOME/seam-gen/build-scripts/build.properties
$SEAM_HOME/seam-gen/build-scripts/build.xml
$SEAM_HOME/seam-gen/build.xml

Enjoy!

Devon

By | 2017-05-18T15:18:57+00:00 August 19th, 2007|Java, JBoss, Seam|3 Comments

About the Author:

3 Comments

  1. Devon August 19, 2007 at 12:45 pm - Reply

    One thing to note: If you are using Eclipse 3.3 (as I am), then this bug:

    https://bugs.eclipse.org/bugs/show_bug.cgi?id=195986

    Will prevent you from using some of the seam-gen tasks from within Eclipse. The use of defaultvalues for user input causes Eclipse 3.3 to throw a NullPointerException. Hopefully we’ll get a fix in 3.3.1.

  2. ngonidan September 6, 2009 at 11:24 am - Reply

    One important thing, so how do we run the scripts/projects above,

    To help out others who might get stuck here,

    Now, there is NO more any need to go to the seam directory to run seam setup etc,

    I quote Devon here:

    The above changes enhance seam-gen to generate targets within the generated project’s ant build script, which in turn call the related seam-gen tasks.

    SO this means each projects build.xml file created from now onwards, has the code added above which enables it to call seam-gen tasks, so to run the above from the command prompt, just change directory to the projects root folder and type ant, by default ant looks for a build file called build.xml if none is specified on the command line and then runs the tasks there in this case resulting in seam-gen tasks being called just like you had type seam setup etc.

    i.e.
    H:\testseammultipleprojects>ant
    Buildfile: build.xml
    init:
    groovy.compile:
    groovy.copy:
    compile:
    [javac] Compiling 3 source files to H:\testseammultipleprojects\
    exploded-archives\testseammultipleprojects.jar
    copyclasses:
    archive:
    [jar] Building jar: H:\testseammultipleprojects\dist\testseamm
    ultipleprojects.jar
    [jar] Warning: WEB-INF\classes\components.properties modified in the futur
    e.
    [jar] Building jar: H:\testseammultipleprojects\dist\testseamm
    ultipleprojects.war
    [jar] Building jar: H:\testseammultipleprojects\dist\testseamm
    ultipleprojects.ear
    datasource:
    deploy:
    [copy] Copying 1 file to C:\jboss-4.2.2.GA\server\default\deploy
    BUILD SUCCESSFUL
    Total time: 23 seconds

    Hope it helps, Saves a couple of hours and hair !!!!!

  3. ngonidan September 10, 2009 at 5:20 am - Reply

    Also just to correct my typo above i case it might be misunderstood, you need to run seam setup initially, but from then on no need !!!

Leave A Comment