31 March 2011

Running ojdeploy from Ant


JDeveloper deployment is built around deployment profiles. A common implementation is an ArchiveProfile that describes the structure of a JAR archive. Deployment profiles can be created as part of a project or workspace. A command-line tool, ojdeploy, is available to allow deployment of ArchiveProfile(s) without invoking the JDeveloper IDE (JDeveloper does not need to run but it needs to be installed in order to run ojdeploy).

Command line deployment requires a JDeveloper installation, but this installation is invoked in 'headless mode' (this means that JDeveloper does not need to run), not displaying the JDeveloper IDE, loading all extensions defined for headless mode. This form of deployment can read JDeveloper applications and projects and their meta-data. Ant scripts to invoke command line deployment need to be created manually. The resulting deployed archive depends on version of JDeveloper used, and which extensions are enabled when command line deployment is invoked.

Export an Ant Build Script That Uses OJDEPLOY From JDeveloper
To make it easier to create an Ant build script for command line deployment, an Ant script can be generated from JDeveloper.

The Ant script will have the following structure:
The build.xml File






The build.properties generated along with build.xml, will define the additional variables needed for command line deployment:
The build.properties File

   #Thu Mar 31 12:42:42 EEST 2011
oracle.jdeveloper.ant.library=C\:\\Oracle\\Middleware\\jdeveloper\\jdev\\/lib/ant-jdeveloper.jar
output.dir=classes
oracle.home=../../../../../Oracle/Middleware/jdeveloper/
javac.deprecation=off
oracle.jdeveloper.workspace.path=C\:\\JDeveloper\\mywork\\tmp\\DependentLOVtest\\DependentLOVtest.jws
oracle.jdeveloper.deploy.profile.name=*
javac.debug=on
oracle.jdeveloper.deploy.dir=C\:\\JDeveloper\\mywork\\tmp\\DependentLOVtest\\ViewController\\deploy
oracle.jdeveloper.ojdeploy.path=C\:\\Oracle\\Middleware\\jdeveloper\\jdev\\bin\\ojdeploy.exe
javac.nowarn=off
oracle.jdeveloper.project.name=ViewController
oracle.jdeveloper.deploy.outputfile=C\:\\JDeveloper\\mywork\\tmp\\DependentLOVtest\\ViewController\\deploy

                                                    \\${profile.name}


The Ant build script can be run outside of JDeveloper by simply changing to the directory containing build.xml and running Ant. It can also be run from within JDeveloper, by right-clicking on the build.xml node in the Application Navigator and selecting the "all" or the "deploy" targets.

(the build file is rendered when running build file but in this post is ommitted)

Buildfile: C:\JDeveloper\mywork\tmp\DependentLOVtest\ViewController\build.xml

init:

deploy:
[ora:ojdeploy] ----build file----
[ora:ojdeploy]
[ora:ojdeploy]
[ora:ojdeploy]  
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]  

[ora:ojdeploy]  
[ora:ojdeploy]    
[ora:ojdeploy]    
[ora:ojdeploy]  

[ora:ojdeploy]

[ora:ojdeploy] ------------------
[ora:ojdeploy] Mar 31, 2011 12:57:42 PM oracle.bali.xml.gui.jdev.JDevXmlContext _setProjectAndAttachDetach
[ora:ojdeploy] INFO: Defensive open of project ViewController.jpr during creation of XmlContext (web.xml)
[ora:ojdeploy] Mar 31, 2011 12:57:43 PM oracle.jdevimpl.deploy.fwk.DeploymentManagerImpl$DeployConsoleLogger willPrepare
[ora:ojdeploy] INFO: ----  Deployment started.  ----
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:43 PM oracle.jdevimpl.deploy.fwk.DeploymentManagerImpl$DeployConsoleLogger printTargetPlatform
[ora:ojdeploy] INFO: Target platform is  (Weblogic 10.3).
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:43 PM oracle.jdevimpl.deploy.common.ProfileDependencyAnalyzer deployImpl
[ora:ojdeploy] INFO: Running dependency analysis...
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:43 PM oracle.jdevimpl.deploy.common.ModulePackagerImpl deployProfiles
[ora:ojdeploy] INFO: Deploying profile...
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:46 PM oracle.jdevimpl.deploy.war.WarDeployer writeWarFile
[ora:ojdeploy] INFO: Wrote Web Application Module to file:/C:/JDeveloper/mywork/tmp/DependentLOVtest/ViewController/deploy/DependentLOVtest_ViewController_webapp1.war
[ora:ojdeploy] Mar 31, 2011 12:57:47 PM oracle.jdevimpl.deploy.fwk.DeploymentManagerImpl$DeployConsoleLogger finished
[ora:ojdeploy] INFO: Elapsed time for deployment:  4 seconds
[ora:ojdeploy]
[ora:ojdeploy] Mar 31, 2011 12:57:47 PM oracle.jdevimpl.deploy.fwk.DeploymentManagerImpl$DeployConsoleLogger finished
[ora:ojdeploy] INFO: ----  Deployment finished.  ----
[ora:ojdeploy]
[ora:ojdeploy] Status summary written to /C:/JDeveloper/mywork/tmp/DependentLOVtest/ViewController/deploy/ojdeploy-statuslog.xml

all:

BUILD SUCCESSFUL
Total time: 11 seconds



Notes: By default, the command line deployment task has the nocompile option enabled as the task has dependency on the compile task. If this dependency is removed then the nocompile option can be removed.

It is a best practice to generate an .ear file from JDeveloper for the application. The .ear file will be generated with all the right class dependencies required to deploy it. Deploying with Ant by referring to an application directly without generating an .ear file may require that dependencies for the classes and jars files must be resolved manually.

 Create an ant build file automatically with JDeveloper

 
Use a New Gallery dialog to create a new Ant buildfile for a Java project.
To create a new Ant buildfile and add it to the selected project:

  • In the navigator, select the project to which you want to add an Ant buildfile. 
  • Choose FileNew to open the New Gallery.In the Categories list, expand General and select Ant. In the Items list, double-click Empty Buildfile. 
  • The Create Ant Buildfile dialog opens. For more information at any time, press F1 or click Help. If you wish, enter other directory and file names for the build file.Click OK.
If you are going to use ojdeploy,  do not forget to tick the "Include Packaging Tasks"




2 files will be created under resources (see begining of the post for more).
  • build.xml
  • build.properties
The new build file is added to your project and opened for editing

Notes
Check also OJDeploy revisited libraries not included in compile via ant

Dig more: 
  • JDeveloper's Help

Deployment Profiles

Deployment profiles are application or project properties that govern the deployment of a project or application. A deployment profile names the source files, deployment descriptors, and other auxiliary files that will be packages, the type and name of the archive file to be created, dependency information, platform-specific instructions, and other information. 

Usage: 
Deployment profiles are used to define the settings for archives in order to deploy an application to an external server.

Some deployment profiles are created at application level (EAR), and some at project level. At application level: EAR (Java EE enterprise archive) files can comprise an application's WAR, EJB JAR, and client JAR files. MAR (metadata archive) files are used to deploy an application's metadata.

At project level, the deployment profiles available depend on the project technologies selected for the project.


Creating and Editing a Deployment Profile

To create a deployment profile: 
  • In the Application Navigator, select the application or project for which you want to create a profile. 
  • Choose FileNew to open the New Gallery. 
  • In the Categories tree, expand General and select Deployment Profiles. In the Items list, select a profile type. If the desired item is not found or enabled, make sure the correct application or project is selected, and select All Technologies in the Filter By dropdown list. Click OK. 
  • In the Create Deployment Profile dialog, enter the name for the profile, and click OK. 
  • In the Edit Deployment Profile Properties dialog, select items in the left pane to open dialog pages in the right pane. Configure the profile by setting property values in the pages of the dialog. 
  • Click OK to close the dialog.

To reopen an application deployment profile to make changes,
  • right-click the application in the Application Navigator and choose Application Properties, 
  • then select the name of the profile in the Deployment section of the Application Properties dialog and 
  • click Edit.



Edit to configure the profile


To reopen a project deployment profile to make changes,
  • right-click the project in the Application Navigator and choose Project Properties, 
  • then select the name of the profile in the Deployment section of the Project Properties dialog and 
  • click Edit.
 To run/activate a deployment profile: 
  • for a project level deployment profile, right-click the project in the Application Navigator then choose Deploydeployment profile. 

  • for an application deployment profile, right-click the application in the Application Navigator then choose Deploydeployment profile. 


The project and any projects on which it depends will be compiled and packaged.


Dig more:
  • JDeveloper's Help

30 March 2011

ojdeploy : Deploying ADF application from Command Line


Applications or modules can be deployed from JDeveloper without actually starting the JDeveloper IDE itself. Deploying from the command line, using ojdeploy, is especially useful where you need to deploy existing projects or applications using a batch file or other script.

Command Usage

ojdeploy -profile -workspace [ -project ] [ ]
ojdeploy -buildfile [ ]
ojdeploy -buildfileschema


Arguments: 
(Argument: Description)
  • profile: Name of the profile to deploy.
  • workspace: Full path to the JDeveloper workspace file (.jws).
  • project: Name of the JDeveloper project within the .jws where the deployment profile can be found. If omitted, the Profile is assumed to be in the workspace.
  • buildfile: Full path to a build file for batch deploy.
  • buildfileschema: Print XML Schema for the build file.


Note: Deployment profiles can be classified into two broad categories, those that are defined at the application or workspace level, and those defined at the project level. To deploy a workspace-profile, ojdeploy takes the workspace location, and the name of the profile. To deploy a project-profile it takes an additional -project argument.

Options
( -Option: Description)
  • -basedir: Interpret path for workspace relative to a base directory. The built-in macro ${base.dir} captures the value of -basedir.
  • -outputfile: Specifies an alternate location for the output. The default is within a \deploy directory inside the project or workspace. If this parameter does not specify a file extension, the extension is determined from the original file name in the deployment profile.
  • -nocompile: Prevents the build system from being invoked. This is useful if a workspace or project just needs to be packaged, and not compiled at this time. 
  • -clean: Deletes all files from the project output directory before compiling. Deployment will stop for that profile, if a file or directory could not be deleted.
  • -nodatasources: For Java EE applications, this prevents the weblogic-jdbc.xml file from being updated with connection information found in the JDeveloper IDE. This option is ignored for non-Java EE applications. More
  • -forcerewrite: Ensures output file is rewritten even if the contents have not changed in this run of ojdeploy.
  • -updatewebxmlejbrefs: Update EJB references in web.xml.
  • -define: Allows for additional macros to be defined on the command-line. This can also be done in an XML build file using the element. Macros and options defined on the command line supplement, or override, those found in the section of a build file if one is being used.
  • -statuslogfile: Full path to an output file for status summary. No macros allowed. The -statuslogfile option will create an XML file that stores a list of all the profiles processed and the status of each. A summary section at the end can be checked to quickly determine the exit status for the entire script.

Built-in Macros
(Macro: Description)
  • workspace.name: Name of the workspace (without the .jws extension).
  • workspace.dir: Directory of the workspace.jws file.
  • project.name: Name of the project (without the .jpr extension).
  • project.dir: Directory of the project.jpr file.
  • profile.name: Name of the profile being deployed.
  • deploy.dir: Default deploy directory for the profile.

Note: The project.name and project.dir macros are only available when a project-level profile is being deployed.

Examples

Deploy a project-level profile: 
  • ojdeploy -profile webapp1 -workspace /usr/jdoe/Application1/Application1.jws -project Project1 
  • ojdeploy -profile webapp1 -workspace Application1/Application1.jws -basedir /usr/jdoe -project Project1
Deploy a workspace-level profile: 
  • ojdeploy -profile earprofile1 -workspace /usr/jdoe/Application1/Application1.jws

Deploy all profiles from all projects of a workspace: 
  • ojdeploy -workspace /usr/jdoe/Application1/Application1.jws -project \* -profile \*

Build in batch mode from a ojbuild file: 
  • ojdeploy -buildfile /usr/jdoe/ojbuild.xml

Build using ojbuild file, pass into, or override default variables in, the build file: 
  • ojdeploy -buildfile /usr/jdoe/ojbuild.xml -define myhome=/usr/jdoe,mytmp=/tmp 
  • ojdeploy -buildfile /usr/jdoe/ojbuild.xml -basedir /usr/jdoe

Build using ojbuild file, set or override parameters in the default section: 
  • ojdeploy -buildfile /usr/jdoe/ojbuild.xml -nocompile ojdeploy -buildfile /usr/jdoe/ojbuild.xml -outputfile '${workspace.dir}/${profile.name}.jar' 
  • ojdeploy -buildfile /usr/jdoe/ojbuild.xml -define mydir=/tmp -outputfile '${mydir}/${workspace.name}-${profile.name}'

More examples
  •  ojdeploy -workspace Application1/Application1.jws,Application2/Application2.jws -basedir /home/jdoe -profile app* 
  • ojdeploy -buildfile /usr/jdoe/ojbuild.xml -define outdir=/tmp,rel=11.1.1 -outputfile '${outdir}/built/${workspace.name}/${rel}/${profile.name}.jar' 
  • ojdeploy -workspace Application1/Application1.jws -basedir /home/jdoe -nocompile -outputfile '${base.dir}/${workspace.name}-${profile.name}'
Quick Overrides Without Editing a Build Script

To pass in macro values or override the ones defined in a build script, use the -define option to supply a new value: 
  • ojdeploy -buildfile /home/user/ojbuild.xml -define "mycustomdir=/tmp"

This will add the mycustomdir variable to the section of the build script, or replace it if it already is defined with the value '/tmp'.

To pass in parameter values or override the ones defined in a build script, use the appropriate parameter option: 
  • ojdeploy -buildfile /home/user/ojbuild.xml -nocompile -nodatasources

This will add the -nocompile and -nodatasources parameters to the default section of the build file.

See related posts (when they arrive) for more info.

Src: 
  • JDeveloper's Help or ojdeploy commands help switch.  I did not manage to find it online :( 

29 March 2011

ADF Essential series recorded presentations and tests at ADF Insider

ADF Insider recorded presentation series got one more excellent addition from Grant Ronald, the Oracle ADF Insider Essentials. Moreover, test your knowledge with ADF Insider Essentials Tasks.
Posting some content to tease you:

Oracle ADF Insider Essentials

ADF Business Components

Programatically iterating through rows of a view object March 2011
A common use case is to be able to programmatically access the rows in a view object. This ADF Insider Essentials shows you how.
Building a dependent list of values March 2011
Find out how you can use the declarative features of ADF Business Components to build a dependent list of values that automatically limit its choices based on another attribute value.
Implementing Sequences in an ADF Applications March 2011
Most, if not all, ADF applications based on database tables will have to manage assigning sequence numbers to unique and primary key attribute values. Find out how you can do this in ADF Business Components.
Extending ADF Framework Security with Resource Permissions March 2011
This sample shows how to use the OPSS Resource Permission in ADF Security to protect an entity attribute from update when an entity row is newly created.

ADF Model

Accessing ADF Binding Layer from Java March 2011
When writing code in a managed bean you might want to access attribute values or execute method calls. This ADF Insider Essentials shows you how you can access ADF bindings from a managed bean.
Synchronizing a Tree Control with Detail Data March 2011
This ADF Insider Essentials shows you how selecting a node in a UI tree component can automatically synchronise that data with a form. The key is to use EL to indicate which iterator should be refreshed.

ADF Controller

Passing Data Within A Task Flow March 2011
In a task flow you may want to reference data or values set up in another activity of the task flow. This ADF Insider Essentials shows you how you can pass data in a task flow.

ADF Faces

Building UI Layout using the ADF Faces Switcher Component March 2011
Sometimes you might want to dynamically switch an area of your page to show a different UI component. This demonstration shows how you can use af:switcher to dynamically change the UI layout.
Storing Different Values to those Displayed Using a selectOneRadio March 2011
For a binary value, such as OrderFilled (Y or N) you may have the use case of storing a Y and N in the dtabase but display different values (e.g. Yes and No, or Filled & Not Filled) to the user. This demonstration shows how you can achieve this with a selectOneRadio component.
Controlling Using Input in Table Column Filters March 2011
This sample shows how to customize the column filter in an af:table component to control user query data input. The sample uses JavaScript to enforce numeric value input on an ID attribute field.
Using af:iterator to Dynamically Render an Image March 2011
How can you dynamically render a UI component a set number of times? For example, for a customer rating (which is a numeric value) you want to "stamp out" a certain number of stars to indicate the rating rather than just display a number (like an Amazon rating). This demonstration shows you how using the af:iterator component.

Oracle ADF Insider Essentials Tasks

ADF Business Components

Programmatically iterating through rows of a view object March 2011
Task: How would you programmatically iterate through the rows of a view object to perform an action on each row. For example, for a selected department, you want to give a fixed pay rise to every employee in that department so you want to programmatically access each employee row and and update their salary.
Hint: This functionality needs to be applied to a single Departments Row but across many Employee Rows. The ViewRowImpl class represents a row in a view object and a RowSet represent the collection of these queried employee rows.
Solution: Click here to watch Grant Ronald walk you through a solution.
Building a dependent list of values March 2011
Task: You would like to limit the choices in a drop down list depending on some other data. For example, a department's location is based on a country and a city. You want to ensure that the drop down list of cities only shows cities in the currently selected country.
Hint: The HR schema defines a Departments table, cities are defined in the Locations table and countries are defined in the Countries table. You will need to ensure your view object contains the required attributes. You can use a model driven list of values to define the drop down list for DepartmentsVO.LocationId. A view criteria is a good way of filtering a view object (on which a model driven list of values is based) and it can be parameterised so you can pass the value of country which will filter the model driven list of values.
Solution: Click here to watch Grant Ronald walk you through a solution.
Implementing Sequences in an ADF Application March 2011
Task: When creating a new record (such as an employee or department) you are required to assign a unique value to the primary key attribute. So, in the Departments table this would be Deptno and in the Employees table this would be Empno. These values should be assigned from a database sequence.
Hint: There are two possible ways to achieve this. The first is when a new Department row is created in the entity object, you can read a database sequence (SequenceImpl) and assign a value. The other option (for Employees.Empno) is to assign the sequence in a database trigger and then allow the framework to automatically refresh the attribute with the assigned value
Solution: Click here to watch Grant Ronald walk you through a solution.
Extending ADF Framework Security with Resource Permissions March 2011
Task: Using ADF Security, you would like to set permissions that some users can only edit data when the row is being inserted. Once inserted, users with this permission cannot update the row.
Hint: You will need to create a new resource type (e.g. insert) and extend the EntityImpl to handle this new case by checking ResourcePermission
Solution: Click here to watch Frank Nimphius walk you through a solution.

ADF Model

Accessing ADF Binding Layer from Java March 2011
Task: You have a form for inputing a new employee and a table showing all employees. On pressing a button you want to do the following: commit the new employee record, filter the table of employees to show employees who are in the department of the employee you just added, and you want to refresh the table to show only those employees.
Hint: Your code should be in a single method in a backing bean. You need to access an action binding for the commit and an action binding to call ExecuteWithParams to execute a where clause or view criteria to filter the data. Remember, you will need to pass in the departmentID of the newly created employee. Finally you need to fresh the table UI component.
Solution: Click here to watch Frank Nimphius walk you through a solution.
Synchronizing a Tree Control with Detail Data March 2011
Task: You have a tree control showing Customers by Country. You also have a tree control showing Customers by Sales Rep. In either of these tree controls, if you select a customer, you should see the details for that customer in a form.
Hint: This is not a master detail data model; CountriesVO, CustomersVO and SalesRepVO should be top-level data collections in your application module. Accessors between the view objects allow the tree control to build the appropriate hierarchy. When you build the tree control you should be able to define that the CustomersVO instance should be refreshed when the node in the tree is selected.
Solution: Click here to watch Grant Ronald walk you through a solution.

ADF Controller

Passing Data Within A Task Flow March 2011
Task: You have a task flow consisting of a search page, a method call to perform the search, and a results page to show the result of the search. So for example, you enter a credit limit value in the search page, this value is read by the method activity to filter all customers with a credit limit greater that this value. You then display the result in the final page which also includes the label/prompt "Customers with Credit Limit greater than" .
Hint: You could use a memory scoped variable to hold the value to be accessed by the various activities in the taskflow. So for example, on pressing a button you could set the value of the memory scoped variable (SetPropertyListener), and you would refer to this variable in the method call and in the label/prompt.
Solution: Click here to watch Grant Ronald walk you through a solution.

ADF Faces

Dynamic UI Layout using the ADF Faces Switcher Component March 2011
Task: Build a page containing a panel inside which you want to display two different styles of UI components that you can switch between by selecting a menu option or pressing a button.
Hint: You can use af:switcher to switch between different UI components.
Solution: Click here to watch Grant Ronald walk you through a solution.
Storing Different Values to those Displayed Using a selectOneRadio March 2011
Task: In your database, for example Orders.OrderFilled, you are storing a single character value Y or N. However, when exposing that attribute to the user as a radio button you would like to display "Yes" and "No" as the data values while still storing Y and N in the data model
Hint: Using ADF Business Components model driven list of values and a read only view object to store the display and data values, you should be able to then easily drag and drop the attribute onto the page as a selectOneRadio
Solution: Click here to watch Grant Ronald walk you through the solution.
Controlling Using Input in Table Column Filters March 2011
Task: For an employees table, you would like to prevent the user from inputing alpha characters for the EmployeeId table column filter.
Hint: You can use the filter facet in a table column to define a component you want to use for filtering that column. You could then use a JavaScript function to be called everytime the key is pressed in that field and check that the value is not an alpha character.
Solution: Click here to watch Frank Nimphius walk you through a solution.
Using af:iterator to Dynamically Render and Image March 2011
Task: Depending on the value in a field, you would like to "stamp" out an image that number of times. For example, if a customer has a rating 1-5 then you would like to display a star that number of times. So a customer with a rating of 3 would displa 3 stars to indicate their rating.
Hint: An af:iterator component can take an array list as its value. The number of elements in that array will define how many times the iterator will stamp out. For a more advanced example, the array could also define which image should be stamped out.
Solution: Click here to watch Grant Ronald walk you through a solution.

 Dig more:






You might also like:

Related Posts Plugin for WordPress, Blogger...