Monday, February 6, 2012

ADF Maven : A little bit of mojo Model project

I was testing the much improved maven stuff in Jdev for my ADF project and found a couple of differences in my produced jar and the ADF ojdeploy produced one.

First I needed to include the xml, jpx and properties stuff in my jar in the build\resources tag:

<resource>     <directory>src/</directory>      <includes>       <include>**/*.xml</include>        <include>**/*.jpx</include>       <include>**/*.xcfg</include>       <include>**/*.properties</include>     </includes> </resource>
Then I needed the adfm.xml and files all the other files where just text files so I am ignoring them for now.

So for this I created a mojo plugin and included it in my build step


      <plugin>         <groupId></groupId>
            <phase>compile</phase>             <goals>               <goal>adfJarMetadataGenerator</goal>             </goals>           </execution>         </executions>       </plugin>

Onto the plugin:
Create a new maven project in Jdev and make surte the packaging is of type maven-plugin.

Then create a java class (your mojo) and extend org.apache.maven.plugin.AbstractMojo
The @goal sudo annotation denotes the name of your plugin that you will use in the calling project.

 * This should generate the extra meta data for adf jar projects.
 * @goal adfJarMetadataGenerator
 * @phase compile
public class ADFClassMetaDataGenerator extends AbstractMojo {

The @parameter annotation denotes and xml tag that you can pass data to your mojo from the calling project.

 * @parameter
private String adfmFileName = "classes/adfm.xml";
 * @parameter  expression="${}"
private File srcDirectory = new File("src/");
 * @parameter
private String svaFileName = "classes/";

You then need an   public void execute() throws MojoExecutionException { method.
This will go though your project and find the location of your Model.jpx file and your bc4j.xcfg this will allow you to generate the adfm.xml.

      StringBuilder adfmBuilder =
        new StringBuilder("\n").append("\n").append("  

Then parse the Model.jpx to find all the application modules for the ResourceService.sva.
StringBuilder svaBuilder =  new StringBuilder("#:__PROLOG__:ADF_LibraryDependencies:!;ADF_DataControl:ADF_BusComps\n");
      //for each data control
for(DataControl dc : dcs) {
      svaBuilder.append("#:__EPILOG__:\n").append("oracle.adf.library.rc.dependencies.LibDepsServiceStrategy ADF_LibraryDependencies\n").append("oracle.adf.library.rc.dcxdatacontrols.DataControlServiceStrategy ADF_DataControl\n").append("oracle.adf.library.rc.buscomp.BusCompServiceStrategy ADF_BusComps\n");

Then just create these files and you are done.

Do a clean install and you can now use the generator in any of your projects.

Note: This is still a work in progress hopefully I get time to finish it off and I will publish the plugin. But it should give you a good idea of what to do.


  1. Great post!
    BTW, does your mojo have any dependency to Oracle ADF library?
    Have you made any progress after this post? If so, is there any chance you could make it available?
    Thanks a lot.

    1. Sorry I did not get any further - project timelines did not allow and I am on a different project now.

      Hopefully I will get back to this at some stage though then I will let you know.

    2. Not a problem.
      Would you mind making make the current code available anyway? I would like to see how you've obtained the data control objects via API.
      Any help will be appreaciated.


    3. Email me at the email address on my profile and I will see what I can do.