In this chapter, we will prepare our development environment and install all the necessary software that we will be using throughout this book. This chapter contains the following recipes:
Preparing and structuring the OS for ADF and JDeveloper
Exploring different options to install the database
Downloading the book's Git repository
Oracle Application Development Framework or ADF is the Oracle end-to-end flagship framework to help increase a developer's productivity by providing ready-to-use design patterns and best practices so that the developer needs only to concentrate his/her focus on the business logic rather than focusing on the technology behind it.
With Oracle JDeveloper as a cross-platform Integrated Development Environment (IDE), Oracle ADF and all Oracle Fusion Middleware suite products find the IDE that simplifies development and supports all development lifecycle stages.
Oracle ADF framework can also be developed with Eclipse IDE. By installing an Oracle Enterprise pack for Eclipse, you can develop ADF applications with Eclipse. For more information, refer to the official documentation at http://www.oracle.com/technetwork/developer-tools/eclipse/overview/index.html.
ADF Faces is responsible for representing data to the end user and taking inputs back, passing data from and to the Data layer, respectively, to process.
In this book, we will highlight our focus on the Oracle ADF Faces section of the ADF Framework, how to utilize it to our needs, and how to make the best data of it to create a beautiful user experience for the end user.
In this chapter, you will learn how to structure your development environment and how to organize and put everything in its right place. You will learn how to install your latest JDK and the options available for your database installation. You will practice how to install JDeveloper and how to tune it for your operational system, and how to change some general preferences inside JDeveloper. You will get an overview of Git and how to install the book's repository on your machine.
It's important to understand the memory consumption of your software in order to work effectively without any trouble. If you would like to have a complete environment to work with ADF effectively, with your local machine, you might need to install JDeveloper and Oracle Database locally—if you like to work offline—which is a lot of memory consumption, not to mention when you debug and run your application against the application server, which would also have a medium to large memory footprint. So, make sure you have enough memory and processing power to start working with ADF effectively.
The following are considered minimum hardware requirements for your development machine:
Minimum 4 GB Memory (RAM)
Fast CPUs (for example, Intel Core i5)
SSD Hard drive, HDD with minimum 7200 RPM, or Hybrid HDD
For more information and guidance about performance and memory, check this great video by Chris Muir at http://www.youtube.com/watch?v=GXABzw7qU9g.
After making sure you have enough processing and memory power, you will still need to prepare your environment. You should always start by creating the directory structure to make sure everything goes into the right place, and to be in control especially after your project expands. It's always a good practice to organize how to reach your information effectively, after which you should start the installation process of your software.
In order to prepare and structure your operating system ADF, perform the following steps:
Create your directory structure properly. What I usually do is start from the root directory of my user, for example,
C:\Users\Amrin Windows or
/Users/amrin a Nix-based OS, and start adding the structure of my development environment. So, in Windows, for instance, my workspace under the user directory looks like the following screenshot:
devdirectory where all the development will reside.
appsdirectory, which will contain all the software starting from JDK to the middleware inside the Oracle directory.
myworkspacesdirectory inside the
devdirectory, which will include different workspaces for each technology—you are free here to make it as per technology or per actual project—and then in each technology you have your different applications.
Create different environment variables for your development environment's
myworkspacesdirectory. This extra step will make it easy when you are installing different software to reach these directories easily using the command line. You should end up with the following environment variables:
$DEV_HOME=/Users/amr/dev $APPS_HOME=$DEV_HOME/apps $WORK_HOME=$DEV_HOME/myworkspaces
You can do the same in Windows by simply navigating to System Properties | Advanced | Environment variables and create three variables with these names:
DEV_HOME=C:\Users\Amr\dev APPS_HOME=%DEV_HOME%\apps WORK_HOME=%DEV_HOME%\myworkspaces
Sometimes you might not have enough security privileges to access System Environment Variables. However, you can achieve the same results by opening the command prompt and using the
setcommand as follows:
set DEV_HOME=C:\Users\Amr\dev set APPS_HOME=%DEV_HOME%\apps set WORK_HOME=%DEV_HOME%\myworkspaces
If you have Mac or other Nix-based systems, you can achieve the previous result by changing the
.bash_profilefile using a text editor or any text editing tools.
I always prefer to use vi or vim when it comes to Nix-based systems, but you can use any text editing tool of your choice. To know more about vi or vim, check these resources at http://www.unix-manuals.com/tutorials/vi/vi-in-10-1.html & http://www.openvim.com/.
export DEV_HOME=/Users/Amr/dev export APPS_HOME=$DEV_HOME/apps export WORK_HOME=$DEV_HOME/myworkspaces
Save by pressing Esc and then :wq
Creating environment variables will help you to map everything accordingly, and will give you a structured development environment for your IDEs and workspaces. This will also help you in your future applications, as you will be able to locate all the information you need in one place, and you will know where you should go fast and easy.
Java Development Kit (JDK) is the engine that runs everything from JDeveloper to the application server. The latest version of the JDK is JDK 7u25 at the time of writing, but if you find a newer version, don't hesitate to use it instead.
Download the latest JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html.
You should download the latest JDK and it should work just fine, but you have to select the JDK suitable for your Operating System and its architecture
You will need an oracle account. This is also important when installing the Oracle Database and JDeveloper, so you should get one now if you don't already have one, and it's free too!
Depending on the operating system, the installation should be straightforward, as for each operating system, there should be an installer with it, for example, for Windows an exe installer, for Mac you will have a dmg, and an rpm for Linux
Change the JDK installation directory to be inside
JAVA_HOMEenvironment variable, and update the
PATHenvironment variable to look at the
binfolder inside our
jdk7_25directory. This will help you greatly if you use the Java command line often.
If you are using Windows, you should add the following environment variable:
You should change the
PATHenvironment variable to the following:
Alternatively, you can achieve the same result as previous by opening the command prompt without going to your environment variable settings and using the
Make sure you put
%JAVA_HOME%as we want the path to reference all the Java executable files such as java and javac
If you are using Mac or any other Nix-based system, you should edit the
.bash_profilefile to be the following:
export JAVA_HOME=$APPS_HOME/jdk/jdk7_25 export PATH=$JAVA_HOME/bin:$PATH
Notice that in Nix-based systems editing a
.bash_profileis little bit different as the separator is a colon and not a semicolon
Defining environment variables such as
JAVA_HOME and putting them inside the
PATH variable is crucial as we might need to start applications using the command line and these variables will become handy during such circumstances. Also, we will need this in order to start the installer of JDeveloper after installing the database.
Now that you have finished the installation of JDK, close any terminals (command prompts) opened and start installing the database.
Almost all enterprise applications have a backend data layer that contains one or more Database Management Systems (DBMS), and since ADF is an enterprise-enabled framework, ADF is no exception to this rule.
Users are encouraged to install a database if they want to follow all the recipes to the letter through all chapters of this book.
ADF works best with the Oracle Database, but as mentioned before it can work with any other DBMS, such as MySQL, PostgreSQL, or MSSQL. For the purpose of this book, you should install the Oracle Database, which comes in two flavors: Oracle Database Standard edition and Oracle Database XE (Express Edition).
There is also an Oracle Database Enterprise edition, which has all the Standard Edition features plus management packs for highly critical performance such as for databases that are used in banks, which is outside the scope of this book.
Oracle XE is a version of Oracle Database that is easy to use and install; however, it only supports Windows 32-bit and Linux 64-bit versions. You can head over to http://www.oracle.com/technetwork/products/express-edition/downloads/index.html and install it if your operating system is one of the supported operating systems. If it isn't, you should install the Oracle Database Standard Edition from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html.
Depending on your operating system, you can know what kind of options you have:
Mac users: You have only one option, and that is to have a virtual machine with Linux or Windows that hosts the database. Oracle provides multiple prebuilt Virtual Machines that you can install from http://www.oracle.com/technetwork/community/developer-vm/index.html.
Linux users: Most of the Linux operating systems are 64-bit; if that is your case, then you are free to install either Oracle Database 12c or Oracle XE 11g. Other than that, you have to install Oracle Database 12c, or you can have a Virtual Machine with the database inside.
Windows users: You can install Oracle XE 11g if your operating system is either 32-bit or 64-bit—you can use the database in its 32-bit mode; however, if you want to run the database on a 64-bit architecture, you can install Oracle Database 12c or you can have a Virtual Machine with the database inside.
Installing the database will provide you with the data that your application will need to display, edit, add, and delete; one example database schema that is installed by default and that we will use in this book is the HR schema.
If you installed Oracle Database Standard edition, you should create at least one instance for you to work with.
Make sure after installing your database that you can connect to it properly, and while the HR schema will be be installed with your database, it'll be locked by default.
In order to unlock the HR schema, log in with your system or sys user and execute the following command:
ALTER USER HR IDENTIFIED BY PASSWORD ACCOUNT UNLOCK;
JDeveloper comes in two flavors: Studio edition and Java edition. If you are not planning to work with ADF in your JDeveloper, you can install Java edition; otherwise, Studio edition is the best when it comes to ADF development.
There are 5 installation options for JDeveloper:
Windows 64 bit
Windows 32 bit
Linux 64 bit
Linux 32 bit
All installation options come with an embedded JDK except for the generic option, for which you need to preinstall JDK.
In this recipe, we will download the generic installation option for the JDeveloper Studio edition and we will install it.
To install JDeveloper, perform the following steps:
Go to http://www.oracle.com/technetwork/developer-tools/jdev/downloads/index.html and download the latest JDeveloper (currently 184.108.40.206.0). Make sure you accept the agreement and pick the generic version from the drop-down menu.
After your download is complete, open your command prompt or terminal and change the directory—using the
command—to the directory that contains the
.jarfile you just downloaded, and then execute the following command line:
java –jar jdev_suite_121200.jar
Note that you can execute the
javacommand directly because you added the
$JAVA_HOME\bindirectory inside the
PATHenvironment variable, and this command basically says, start a Java application from the JAR file provided.
There are a couple of other arguments you can add to the previous command line such as
The previous argument uses another temp directory instead of the Java default one. If you don't have space in your system directory, you can also control the memory footprint of the Java program by adding the –xmX and –xmS arguments as well.
After executing this command, you should be able to see the JDeveloper installer screen as shown in the following screenshot:
If you have other middleware versions, you should install 12c on a different middleware directory, for example,
If you followed everything right and launched the JAR file with Java 7, the next step (prerequisites check) should pass without a problem. Click on Next and have a look at the summary of what will be installed by JDeveloper. Click on Install and let it install your favorite IDE that you will use during this book.
After a couple of minutes you should feel good as your JDeveloper is ready to go. Click on Finish Installation without opening JDeveloper and click on Finish to close your installer.
When you executed the Java command, you started the JDeveloper installation process. Since we downloaded the Studio Edition, it'll ask you about your middleware home directory since it expects you to have multiple middleware products installed.
When you choose a middleware home directory, make sure not to pick up any existing middleware homes as different versions' installation on the same directory can cause lots of troubles.
First we need to create a new environment variable, which will point to the root directory of all our ADF applications; the environment variable needs to be named
You can set the environment variable in Windows to be under the
WORK_HOME directory by executing the following command in the command prompt:
set JDEV_USER_HOME = %WORK_HOME%\adf
For the Nix-based version the environment variable can be set by using the following command:
export JDEV_USER_HOME = $WORK_HOME/adf
JDEV_USER_HOME is a reserved name that JDeveloper looks for before starting; if it's defined, JDeveloper will automatically create new applications in the directory.
JDEV_USER_HOME, all other JDeveloper versions you have in your operating system will be affected as well. If you want to still work with other older JDeveloper versions, make sure you don't create it as an environment variable and rather create a small Windows or Nix batch file to start JDeveloper which sets this variable for the session lifetime only. Check the Git repository, for example, of batch files at https://github.com/agawish/ADF-Faces-Cookbook/tree/master/Chapter%201.
After setting the variable, we need to tune some configuration of JDeveloper before starting it and we are going to use the next recipe for that.
In order to tune JDeveloper, perform the following steps:
Open your Oracle Home directory that we set up when installing JDeveloper, and navigate to
jdeveloper. There are two files that you want to change: the first file is
Open the file using your favorite text editor and locate the following lines:
AddVMOption –Xms AddVMOption -Xmx
You may want to increase these values if they are very low, for example, if you have more than 4 GB of RAM, you should set it to 1 GB each as shown in the following code:
AddVMOption –Xms1024M AddVMOption –Xmx1024M
Save and close the file.
jdev\bin\jdev.confpath under the
Add the following entries at the end of the file:
# optimize the JVM for strings / text editing AddVMOption -XX:+UseStringCache AddVMOption -XX:+OptimizeStringConcat AddVMOption -XX:+UseCompressedStrings # if on a 64-bit system, but using less than 32 GB RAM, this reduces object pointer memory size AddVMOption -XX:+UseCompressedOops # use an aggressive garbage collector (constant small collections) AddVMOption -XX:+AggressiveOpts # for multi-core machines, use multiple threads to create objects and reduce pause times AddVMOption -XX:+UseConcMarkSweepGC AddVMOption -XX:+UseGCOverheadLimit
These settings ensure that your JVM is optimized for your operating system. Also note that some of them are tailored depending on your Operating System architecture. So, don't just copy and paste them. Check what can apply and add accordingly.
Start JDeveloper now. You have tuned it for your operating system, and now it's time to change some general preferences of JDeveloper itself. So, let's start by starting your JDeveloper as shown in the following screenshot:
When you get a prompt that asks which mode you want to choose, leave the default value of the Studio Developer (All Features) option and click on OK.
Change the following inside preferences:
Environment: Change the Encoding to UTF-8
Navigate to Code Editor | Line Gutter and enable Show Line Numbers
Navigate to Run | Weblogic and click on Load Extension and enable FastSwap
Enable external tools by navigating to Tools | External Tools and making sure every item is selected and then clicking on OK.
JDeveloper, like all IDEs, has configuration files that can be used to tune it to work without having memory problems. These configuration files are
The first file controls the main JVM memory parameters that the JDeveloper thread will start using, and
jdev.conf is used to add any additional configuration to the JDeveloper in order to enhance its performance with multicore processors or 64-bit architecture systems.
After that, we started JDeveloper for the first time and you were prompted to select a Role or Mode. Each role is tailored towards a specific behavior.
There are 5 roles you can choose from:
Studio Developer (All Features): This includes all the features of the IDE
Customization Developer: This allows the developer to create customizable applications using the Oracle Metadata Service (MDS) framework
Database Edition: This gives access to the core database development tools
Java EE Edition: This includes features of core Java EE development only
Java Edition: This includes only features of core Java development
After starting JDeveloper, we also need to tune the JDeveloper preferences themselves. This is different since you have control over them from the JDeveloper IDE. So, you may want to change them while you are working. Secondly, it doesn't relate to the JVM thread but it's totally an application-specific property.
Doing these changes to the JDeveloper preferences can increase your performance time by preventing you from facing some problems with encoding and other stuff when you are working with other team members or a multilanguage application.
If you want to explore more properties that you can tweak with JDeveloper beyond the scope of this book, check the ADF EMG discussion at https://groups.google.com/forum/#!topic/adf-methodology/g3q8TgHtsbk.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. You can also download the files from GitHub at https://github.com/agawish/ADF-Faces-Cookbook/archive/master.zip. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
In order to keep your code organized, especially with bigger numbers of team members, you need to have a source control system. There are all sorts of version control systems starting from CVS passing by the famous SVN to the new distributed version control systems such as Git and Mercurial, which offer a different model, particularly for offline usage.
Git is a free and open source distributed version control system; you can learn about it very easily at http://git-scm.com/documentation.
Git also has a tiny footprint with lightning-fast performance. It outclasses SVN, CVS, Perforce, and ClearCase.
You don't have to follow the trend in here, just use what you and your team feel comfortable with.
I chose Git as a repository to have all the example applications used in this book.
You can check the book's repository content at https://github.com/agawish/ADF-Faces-Cookbook and start navigating through the code samples and files for each chapter. You can also download the whole thing and you can contribute if you find any bug or want to make some edits.
The great thing about JDeveloper, especially 12c, is that it comes with Git by default. So, you don't need to install anything. One thing you need to know is that terminology is quite different from SVN.
The command is named Clone because of the distribution nature of Git, as you really clone the project locally on your machine
Leave the name as original, add https://github.com/agawish/ADF-Faces-Cookbook.git to the repository URL, enter your Github username and password, and click on Next.
If you entered your information correctly, you should see the branch master in the Include list. This is another great feature. When you have a stable project, the main code base should be in the master branch, but if you decided to implement other features, you may want to create a new branch and migrate it to the master branch when you finish.
Click on Finish after you finish and you will have the entire book's Git repository locally.
Click on No when you are prompted to create a project out of the Git repository. However, you don't want to choose that option since the repository contains multiple applications.
Access specific applications from the filesystem.
JDeveloper uses the concept of plugins or extensions. With each extension comes a set of features that can manipulate your project in a certain way.
With Git you get all the advantages of having a distributed version control system inside your IDE. You can commit your code within JDeveloper without the need to leave JDeveloper, which will increase your productivity and decrease the time you need to spend using third-party applications to manage your project.
To know more about Git, check the original website at http://git-scm.com/. Also, check these references at http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide for a practical definitive guide to getting started with Git.