A series of how-tos for Oracle JDeveloper to build ADF Applications with Apache Maven. No, I will not teach you Apache Maven, neither Oracle ADF. I will share my experience with Oracle JDeveloper on working with Maven and ADF. “But Maven ADF… that is supported in JDeveloper since version…”, yes, I know, let’s talk about it, though.
Throughout this series, I will help you to have a better experience when using Maven as the build tool for an ADF Application. Focusing on the Maven building tool, we will go through the development of a multi module ADF Application with a Common Workspace – the typical implementation of the Cylinder Pattern (see Figure below), one of the ADF Architectural Patterns. In case this is not your architectural choice for the moment, no worries! As you will see, tasks like building an ADF Application with a Model and a View-controller Project with Maven, do not depend on your architecture.
In order to follow this series, you should be familiar with the basic concepts of Maven and ADF Applications development. The code provided only serves demonstration purposes and it was developed with ADF 22.214.171.124 and Maven 3.3.9. You can check it out here. Let us start!
Building and deploying an ADF Application with Maven
Why creating custom Applications and Projects when JDeveloper offers templates, such as ADF Fusion Application, ADF Model Project, ADF ViewController Project and so on?
Although such templates are very useful for less experienced developers, tutorials, demonstrations, etc., when using Maven as the build tool, we want to have a better control over the project’s structure and its dependencies. Therefore, instead of using templates and having to delete files and dependencies, we will create custom Applications and custom Projects. Furthermore, we will add features and dependencies to our project, as we need them.
I will guide you through the steps to create, build and eventually deploy a custom ADF Application with Maven. This ADF (demo) Application shows a list of employees saved in the Oracle HR Schema. Hence, I will also show you how to create the respective ADF Model and View-Controller Projects.
Creating an ADF Custom Application to build with Maven
In the New Gallery:
- Choose Custom Application;
- Name your application and set the Application Package Prefix;
- Use Maven as the build environment;
- JDeveloper automatically adds a Project1 to the Application. Either click Finish and delete the project afterwards, or create it following the steps described in the next sections. In the former case, do not forget to delete the respective Dependency in the application pom.
At this moment the application’s workspace has the application descriptor (jws file) and the application pom. Let’s create the projects.
Creating an ADF Model Project to build with Maven
In the New Gallery:
- Choose Custom Project;
- Name the project; Select Maven and ADF Business Components among the available features. You can add more features now, or let JDeveloper add them as you create resources;
- Configure the Maven Settings and check the option to Modify normal project structure to match the default maven structure.
- Set the Default Package and click Finish.
After the steps above, the application pom is updated with the child module and dependency to the project that has been created.
Creating an ADF View-Controller Project to build with Maven
- Repeat the steps to Create an ADF Model Project to build with Maven, but this time select the features Maven and ADF Faces.
Building the ADF Application with Maven
Ok, we have created the ADF application and its resources, namely the Model and the View-Controller Project. Now let’s actually build the ADF Application with Maven!
When building ADF resources with Maven, it is important to understand the role of the two maven plugins provided and described by Oracle as:
- ojmake – can be used for applications and projects that don’t involve any deployment, for example, projects with no deployment profile defined;
- ojdeploy – can handle the build of any application and project (including any that involve deployment). You can think of it as a super-set of ojmake.
In order to build the ADF application’s EAR with Maven, we need two deployment profiles. One for the WAR and another one for the EAR. In the other hand, the model JAR is created without a deployment profile.
Notice when I say „package, install, clean, etc.“, I mean „execute the Maven goal package/install/clean etc.“. So, either you use JDeveloper by right clicking on any project’s resource and selecting Run Maven or use the command line. Either way, the result must be the same as long as you use the same Maven version.
Building the ADF Model Project JAR
In the Model Project’s pom file:
- Delete the maven ojdeploy plugin and the default deployment profile in the Deployment section within the Project Properties dialog;
- Add the ojmake maven plugin;
- Package the project and look into the generated JAR within the target directory. You should see your business components under the package you define for your project and the adfm.xml file under the META-INF folder. There are more files we do not need, such as the projector descriptor and the pom file but let’s leave them there for now.
- Install the project so this artifact will be found as a Maven dependency when it builds the ADF View-Controller Project.
Building the ADF View-Controller Project WAR
- Add the maven-war-plugin to the pom file and set the webappDirectory parameter;
- Create a WAR deployment profile through the Project Properties in the Deployment section.
- The last step automatically adds the ojdeploy maven plugin to the application pom file with the reference to the deployment profile you just created;
- Make sure all the maven dependencies defined in the pom file have the scope provided, except the one to your Model project, which must be compile. This will define which libraries go into the WAR’S WEB-INF/lib folder;
- Package the project and look into the generated WAR within the target directory. You should see your web resources and the WEB-INF folder;
- In the Project Properties dialog, edit your WAR profile’s properties, under the File Groups sections, unselect the model project’s folders in the WEB-INF/classes Filters. You don’t need these files once they are already in the WEB-INF library. This has to be done after packaging the application, otherwise Jdeveloper won’t show you the classes folder under the Filters.
Building the ADF Application EAR
- Create an EAR File deployment profile. This will add the ojdeploy maven plugin to the application pom file;
- Open the Deployment Profile Properties, in the Application Assembly section, select the WAR profile you created for your ADF View-Controller Project;
- Package the application and look into the generated EAR. Besides the application resources such as database connections, you will notice that the included WAR does not have the name as described in the View-Controller Project’s pom file. It has the name of the WAR profile, instead. In case you want to avoid this, change the WAR file path and name in the Deployment Profile Properties. IMHO, either I am missing something, or Oracle could improve this part.
Deploying the ADF Application with Maven
Once we have built the ADF Application with Maven it is time to deploy it… with Maven, of course! In order to deploy the application to a Weblogic Server (WLS) instance, we use the maven plugin weblogic-maven-plugin. This plugin can be used for other useful tasks on a WLS, but for now we only use it to deploy the application. To do so, you have to add the plugin on your application pom file.
Notice, I chose to deploy the application during the Maven phase pre-integration-test, but you can choose another one. See the code below.
And for now, we are done with all this Maven ADF stuff! In this post I have showed you how to build and deploy an ADF Application with Maven, using JDeveloper – let’s say, the basic stuff. Anyways, there is more to come with the series When Maven Builds ADF.
Stay tuned and see you soon.