Monday 27 June 2011

JDeveloper Project-POM Synchronization

As part of JDeveloper 11.1.2.0.0 release, we have improved  Maven support in the IDE. One of the Maven features is the automatic synchronization between the JDeveloper Project (jpr) and Maven POM. This blog illustrates this features.

Step 1: Go ahead and create a custom project in JDeveloper.

Step 2: Next, create a POM for this project from the New->Gallery->General->Maven->Maven POM For Project option.

Step 3: Let's add a library to the project. Go to 'Project Properties->Libraries and ClassPath' and add 'Apache Ant' to the project by clicking the 'Add Library' button and choosing Apache Ant from the libraries list.


Step 4: Select Maven->Dependencies in the Project Properties dialog and you will see the Apache Ant added to the pom.

Step 5: Let's add a dependency to the POM and see what happens!. In Maven->Dependencies dialog, click 'Add Library'. Let's choose jstl and add it to the pom. You will see a dialog letting you know that JDeveloper will install the jstl library to the local Maven repository. Say ok in the dialog.


Note: Would be nice to have the export option automatically selected (which is the default in case of adding libraries from 'Libraries and ClassPath' page).

Step 6: Now, select 'Libraries and Classpath' in Project Properties and you will see the jstl library added to JDeveloper project (jpr file) as well.


Click 'OK' in the Project Properties diaog.

So, with this release JDeveloper automatically keeps the jpr and pom in sync whenever dependencies are added to jpr or pom.

Step 7: What if you directly add a dependency to the pom file through Source editor? Let's see what happens in this case. Add the following to pom.xml (from the Source Editor of pom.xml)

        
        <dependency>
          <groupId>oracle.jdeveloper.library</groupId>
          <artifactId>EJB</artifactId>
          <version>3.0</version>
          <type>pom</type>
          <scope>compile</scope>
        </dependency> 

After adding this, go to Project Properties->Maven->Dependencies page and you will see a message in red color
        "The project POM has dependencies that are not in this list. Use 'Add From POM' to add them"


JDeveloper recognized that there is a dependency entry in pom which needs to be added to this list, so project and pom can be kept in sync.
        
Click "Add from POM" button and the EJB library will show up in the Maven Dependency panel and the library will get added to the project as well. Go to 'Libraries and Classpath' to see this entry.




Note:  
If you select the newly added dependency (EJB) and click on 'View' button, you will notice that the Class Path is pointing to the maven local repository. Click some other library (say Apache Ant) and check its Class Path (it will be pointing to your oracle JDeveloper install).
        
Would be a nice if JDeveloper had set the Class Path to JDeveloper install rather than the maven local repository (since the library is already there in the JDeveloper install).
        
Currently, JDeveloper is constructing the description by cancatenating groupId:artifactId:version:type
from the dependency section of the pom. JDeveloper could have used the artifactId "EJB" in the description
column rather than 'oracle.jdeveloper.library:EJB:3.0:pom'. 

JDeveloper: 11.1.2.0.0

Enjoy!. Hope you find this blog useful!.