Pages

Monday, June 13, 2011

Building with Maven in JDeveloper 11gR2

With JDeveloper 11gR2 you can use Maven 2 as your build engine, before 11gR2 you could download a plugin which did not work great because all the required Oracle libraries which were not available in a public repository. So you had no choice to add them manually to a Maven Repository before you can use Maven. With 11gR2 Oracle fixed that by adding your projects libraries to the local Maven Repository when you add a Pom.xml to your projects.

Using Maven in JDeveloper is not that simple and I hope that this blogpost can help you to use maven as your buidtool.

First check if you have in your user profile a folder called .m2 . This folder must contain a settings.xml file ( you can copy it from jdeveloper\apache-maven-2.2.1\conf ) And also add a sub folder called repository.


Select for example your model project and add a Maven POM for Project to this project


You will get a POM overview which matches with your project.


This will add the libraries of the model project to your local Maven repository.


Now you can do the same for the ViewController project.


The only thing missing is the application workspace POM.xml which build all workspace projects. Add the Application POM to your workspace.


Don't enable Generate POM for Projects in this Application because we already did that.


This Application POM is located in the Application Resources window and only contains the Model and ViewController references,

In the project options or when you select the POM.xml you can change the Maven settings


Add some extra Maven goals to your project.


or add some extra Maven Repositories, like your company one.


Too bad indexing the Maven repositories ends in a error. Even when I use my own repository. You can ignore this error.

This is fixed in the 11gR2 patch and now it is working fine.

Now its time to build your project by running the Maven Package Goal.

The Model project was no problem.

The ViewControler project was different.

First I got a Apacle Trinidad error ( the ADF Faces Runtime needs a Trinidad pom )
Cannot find parent: org.apache.myfaces.trinidad:trinidad for project: null:trinidad-api:jar:null for project null:trinidad-api:jar:null

You can try to add and remove the right dependency  ( oracle.jdeveloper.library:ADF-Faces-Runtime-11:pom:11.1.2.0.0 ), maybe this will fix it.

This is fixed in the 11gR2 patch and now it is working fine.

In the Maven setting you can Add or Remove the library dependency.


You will get a message that the local repository will be updated.


In case of the Apache Trinidad error. I need to update the trinidad pom in my local repository and remove the  missing parent and move the groupId and version element,

This is fixed in the 11gR2 patch and now it is working fine.
<!--
  <parent>
    <groupId>org.apache.myfaces.trinidad</groupId>
    <artifactId>trinidad</artifactId>
    <version>2.0.0.1-SNAPSHOT</version>
  </parent>
-->
  <groupId>org.apache.myfaces.trinidad</groupId>
  <version>2.0.0.1-SNAPSHOT</version>
  <artifactId>trinidad-impl</artifactId>
  <packaging>jar</packaging>

and so it goes on and on. Also need to do this for the 2 RichClient Faces POMs located in .m2\repository\oracle\adf\view\faces
Somehow the parent POM of the Oracle and Apache POMs are not added to  the local repository.

And it would be great if Oracle made a option to force the synchronization of all the Jdeveloper libraries ( disc  space is not a problem anymore and make it complete )  and even a option to export these POMs to your own Maven Repository.

The ViewController project has a dependecy with the model project so you need to make sure that the ViewController project can find the Model jar. To do so I will add my own Maven Repository to all the projects.


Change the Settings.xml of Apache Maven or of your local Maven repository and the add the username password which can upload the model artifact.

In the Model POM add a Distribution so Maven can upload the model artifact.

The ViewController can now find the Model dependency and you can create the WAR. This is a big one (130) because it adds all the reference jar to the web-inf/lib. You need to control this by deselecting the export option in the Maven project dependency.

To solve the Apache Trinidad dependency you need to add the Apache repository on the ViewController maven repositories. Add https://repository.apache.org/content/repositories/snapshots/ as url
Open the ADF-Faces-Runtime-11-11.1.2.0.0.pom located in .m2\repository\oracle\jdeveloper\library\ADF-Faces-Runtime-11\11.1.2.0.0\ and change the Trinidad dependency from 2.0.0.1-SNAPSHOT to 2.0.0.3-SNAPSHOT
The 2.0.0.1-SNAPSHOT does not exists in the Apache repository anymore.

This is fixed in the 11gR2 patch and now it is working fine.


Do the same for Trinidad-Runtime-11-11.1.2.0.0.pom  located at .m2\repository\oracle\jdeveloper\library\Trinidad-Runtime-11\11.1.2.0.0

This is fixed in the 11gR2 patch and now it is working fine.



Also got a Maven Package Goal error when I run this Package Goal twice. It is solved when I do a clean first.
Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor

message             : Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor
cause-exception     : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message       : Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor
class               : org.apache.maven.plugin.war.util.WebappStructure
required-type       : org.apache.maven.plugin.war.util.WebappStructure
path                : /webapp-structure
line number         : 1

15 comments:

  1. I have gone through your post which seems to be more informative. You have explained about the "Maven in JDeveloper" in the detailed manner.

    Thanx!

    ReplyDelete
  2. This will not work. There is no simple way to modify "adfm.xml" file. So resulting jarfile will be built but in many cases will not work properly.

    ReplyDelete
  3. Hi,
    I'm trying to use maven in jdev, but i have some dependency problems :

    For model project :
    Cannot find parent: com.sun:codemodel for project: com.sun.codemodel:codemodel:jar:null for project com.sun.codemodel:codemodel:jar:null

    For view project :
    Cannot find parent: oracle.adf.view.faces:adf-faces for project: null:adf-richclient-api:jar:null for project null:adf-richclient-api:jar:null

    i post a message in OTN :
    https://forums.oracle.com/forums/thread.jspa?threadID=2288165&tstart=0

    Do you have any idea ?

    Thanks in advance

    Clément

    ReplyDelete
  4. Hi,

    Did you have these issues on the 11gR2 version which is released today. They fixed some maven issues.

    http://www.oracle.com/technetwork/developer-tools/jdev/jdev-11gr2-nf-404365.html#bugs_fixed_in_11.1.2.1.0

    thanks

    ReplyDelete
  5. No...
    I download it now, and try it.
    I'll give you my feed back
    Thanks

    ReplyDelete
  6. So... it was a bug! With jdev 11gR2, no more problem!

    An other question... is it possible to create an "adf library jar" with maven?

    Thanks

    ReplyDelete
  7. Hi,

    Good to know. I think maven is not very usefull for ADF development.
    For Java etc it is very nice.

    You need to use ojdeploy for making the ear and adf jars. My big frustation. Oracle need to support these artifact in maven or ant.

    Until then don't use maven or call ojdeploy from maven and do things double.

    thanks

    ReplyDelete
  8. We use maven since 2 years in our ADF development (ant task in jdev) without so much problem. But you're right, it's not the best way (some config files are missing, and have to be created ourself).

    I'll try to use ojdeploy in maven using ant. Perhaps the better solution for now?

    thanks

    ReplyDelete
  9. ojdeploy in maven using ant is not a good idea at all...

    You said that :
    "The ViewController can now find the Model dependency and you can create the WAR. This is a big one (130) because it adds all the reference jar to the web-inf/lib. You need to control this by deselecting the export option in the Maven project dependency."

    I've generated a war : 295 Mo!. Checking or not the "export option" doesn't change anything. i have to change "scope" from compile to provided, and no adf library are imported, so the war has a size of 136 Ko!

    I can't find how to import only usefull librairies : when i only use one adf library with "compile" scope, it's seem that all adf libraries are imported!
    Do you have any idea?

    Thanks in advance

    Clément

    ReplyDelete
  10. Hi again!
    My war was using "ADF Libraries".
    I remove them and select jar after jar, the ones really used in my application ("Adf Library" contain too much jars!).
    Result : my war has a size of 25 Mo, a good size (less than 10% of war size using ADF Libraries!).

    ReplyDelete
  11. Hi,

    So for the libs we need to change scope to provided. And manually add the jars to the war.

    But how do you generate the ear , use ojdeploy and building is done again. Or do you it manually and include the required files with the possibility we include old outdated files.

    Thanks

    ReplyDelete
  12. Did you resolve the "Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor" issue. I am struggling with this one too. What finally worked was to do a "maven clean" before running "maven project". I would prefer a better solution though.

    ReplyDelete
  13. Hi,

    indeed you need to clean when you got this error, very strange. Don't know a workaround for this.

    thanks

    ReplyDelete
  14. Hi Clement.

    What did you do

    My war was using "ADF Libraries".
    I remove them and select jar after jar, the ones really used in my application ("Adf Library" contain too much jars!).

    Do you mean the war deployment profile in the projects options and not in the maven settings area.

    and where did you add the jars. also in the war deployment or somewhere in the war or pom.

    thanks

    ReplyDelete
  15. Hi Edwin,

    I add jar using "Add from Repository" in maven dependencies => pom file is updated automaticaly as "Libraries and Classpath" in jdev (added as jar).

    To compile the war, i only use "package" in the maven goal.

    I always have few blocking problems : that's why i decided to stop using maven extension. I will use maven as i used it before : build pom file "in one's hand".

    I hope that maven extension will evolve : it need few more things to be really usefull in big projects.

    Thanks

    Clément

    ReplyDelete