« September 2008 | Main | November 2008 »

October 2008 Archives

October 23, 2008

ADF in Action: Migrating to JDeveloper 11.1.1

Since JDeveloper 11.1.1 has been released on OTN, a number of posts have done on the new features of JDev 11g. We will use all these blogs to complete our task...

Why migrate? Can't we stick with the old 11g?

When a new production release is available it is better to migrate to this release as long as it makes sense. With JDeveloper 11.1.1 this makes perfect sense, because all previous version where just technical previews and not intended for production. Many of us hit one or the other problem and sometimes nearly all of our work was lost. For this reason we happily migrate to the production release.

Start the Migration

Stop, hold it. Not so quick! Before we start migrating, we make a backup copy of the complete application directory. Just in case we want to return to our old version.

Now, we are ready to start. Since migration from Technical Previews to Production Releases is not supported, we take the JDeveloper 10.1.3 version of the project and copy it to the 11g directory. To get the application workspace into JDeveloper we open it with Open Application ... in the Application Navigator. JDeveloper will tell us that the project files will be migrated. This what we want. Great, go ahead. A quick scan through all the projects looks pretty promising. OK, let us continue.

The Database Project

This is easiest project. We can check the database connection from Application Resources -> Connections -> Database -> survey. On my copy the login details where gone. This is a security measure and acceptable. After supplying the necessary details, the connection to the database should work like a charm. If you do not have your database up and running, restart it.

The ModelTopLink Project

OK, move on to the ModelTopLink project. Nearly everything is fine here. But we have to check the libraries and the client must be changed a bit. To change the libraries open the Project Properties (double-click on the ModelTopLink project), select Libraries and Classpath. You need only the libraries Oracle XML Parser v2, EJB 3.0, TopLink, Java EE 1.5 API, and WebLogic 10.3 Remote-Client. Everything else should be removed.

Finally we need to adjust the code of the SurveySessionClient a bit.

1. The parameter for the context.lookup() has to be changed to

(SurveySession)context.lookup("SurveySessionBean#demo.survey.model.toplink.SurveySession");

2. The method getInitialContext() needs some extra settings to connect to the integrated WebLogic server:

private static Context getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
// WebLogic Server 10.x connection details
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7101");
return new InitialContext(env);
}

To avoid problems while testing, click on the ModelEJB30 project, open the Context Menu and choose Remove from OnlineSurvey.jws. Click on the SurveySessionBean, open the Context Menu and select Run. When you see [Application OnlineSurvey deployed to Server Instance DefaultServer] in the Running: Default Server - Log window, click on the SurveySessionClient, open the Context Menu and select Run. The output should show that the client is working.

The ModelEJB30 Project

This project is similar to the ModelTopLink project: we have to check the libraries and the client must be changed a bit. If the ModelEJB30 project is not in your OnlineSurvey application, go to the Application Menu left to the OnlineSurvey name and select Open Project ..., in the Open Project file selector navigate to the ModelEJB30 directory and select the ModelEJB30.jpr file.

To change the libraries open the Project Properties (double-click on the ModelEJB30 project), select Libraries and Classpath. You need only the libraries Oracle XML Parser v2, EJB 3.0, TopLink, Java EE 1.5 API, and WebLogic 10.3 Remote-Client. Everything else should be removed.

Finally we need to adjust the code of the SurveySessionClient a bit.

1. The parameter for the context.lookup() has to be changed to

(SurveySession)context.lookup("SurveySessionBean#demo.survey.model.ejb30.SurveySession");

2. The method getInitialContext() needs some extra settings to connect to the integrated WebLogic server:

private static Context getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
// WebLogic Server 10.x connection details
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7101");
return new InitialContext(env);
}

To avoid problems while testing, click on the ModelTopLink project, open the Context Menu and choose Remove from OnlineSurvey.jws. Click on the SurveySessionBean, open the Context Menu and select Run. When you see [Application OnlineSurvey deployed to Server Instance DefaultServer] in the Running: Default Server - Log window, click on the SurveySessionClient, open the Context Menu and select Run. The output should show that the client is working.

The ModelBC Project

Finally, the ModelBC project. You will notice that you have a second ModelBC0.jpx file in the Application Navigator. This will be used in the future. Everything is fine so far and no further actions are to be done.

Exercise

Because the creation of the database is quite a tedious task, create an Ant file to drop the old schema, create the tablespace, create the user, and create the tables of the schema. It might be necessary to change the some of the SQL files.

Coming Up Next

The next post will start building the UI part of the application.

October 31, 2008

Nice JDev 11g Feature: EAR Packaging

While working on the samples for JDeveloper hands-on workshops and on the ADF in Action series, I stumbled into this nice feature...

EAR Packaging with JDeveloper 11g

In previous releases of JDeveloper a number of different strategies have been used to ensure a proper EAR file packaging. Very common is the usage of Ant or Maven scripts, because these are useful for daily builds.

Background

The JDeveloper IDE has the concept of Applications and Projects, if we translate Application to Enterprise Application and Project to Module, we are right in the Java EE nomenclature and can easily understand how to create an Enterprise Application Archive (EAR) with modules like Web Application (WAR), Enterprise JavaBeans (EJB JAR) and so on. With this background information we are able to locate the necessary deployment profiles for each part of the final application.

Each project has its own deployment profile, eg WAR file for a web application or JAR file for a library project. But if you want to put everything together, where do find it?

The Application Deployment Profile

Exactly, the application itself will hold the deployment profile for the EAR file. To find it we need to go to the Application Properties. Application Properties? Where are they? They are located at the Application Level:

  1. Open the Application Navigator
  2. The topmost element is a drop down box with the names of the applications in your IDE. Right next to the drop down box you find the application menu. Click on it and open the Menu. There, at the end of the menu you will find the entry Application Properties! Select it and you will open the Application Properties window.
  3. Select the Deployment entry to go to the Deployment Profiles overview. On the first time it is empty.
  4. To create a deployment profile, you must click on the New... button. The Create Deployment Profile window appears and you can select the Archive Type. On this level only the type EAR File is avaiblable and useful.
  5. Give the profile a Name and click OK.
  6. Once created you are able to edit the EAR Profile Properties.

Edit the Appliction Deployment Profile

The Edit EAR Deployment Profile Properties window allows you to edit the Application Assembly, ie. which modules, er project results, are part of your EAR file, or the Filter Groups.

Bonus: Locate and Edit the Application Deployment Descriptors

To locate and edit the Application Deployment Descriptors you have to expand the Application Resources accordion in the Application Navigator. The Descriptors group contains all the deployment descriptors used at the EAR level. If you want to add a Java EE or product specific deployment descriptor click on META-INF and open the Context Menu. It will contain the three entries New JEE Deployment Descriptor, New Oracle Deployment Descriptor and New Weblogic Deployment Descriptor. All three open a window to select the specific deployment descriptors from.

Enjoy.

 


JDev 11g: Packaging Libraries at EAR Level

Many users have problems to use their libraries in their applications. But sometimes a working solution is too obvious to be noticed.

To include all the libraries you need for your project in an EAR file:

  1. Create a package project called common-libs and put all the libraries in a directory included in the Project Source Path. Don't use the src directory but lib at the same hierarchy level. Add this new directory to the Project Source Paths.
  2. Open the Application Properties
  3. Create a deployment profile for the EAR file.
  4. To include the libraries within the EAR file we have two options to include the libraries are available: either put into APP-INF/lib or a directory of your choice (eg. lib). In the Deployment Profile select Application Assembly, tick the check box of every JAR file you need and enter the directory name (APP-INF/lib or lib) in the Path in EAR text field at the bottom. This must be done for every JAR file!
  5. If you do not want to use APP_INF/lib you need to create an application.xml for the application. Open the Application Resources accordion and expand Descriptors and META-INF to see which Deployment Descriptors are available. On Descriptors, chose New JEE Deployment Descriptor... from the Context Menu and select application.xml. In the newly created application.xml insert the tag <library-directory>lib</library-directory>.
  6. From the Application Menu select Deploy to EAR File to check the contents before deploying it to the server.


About October 2008

This page contains all entries posted to Olaf Heimburger's Blog in October 2008. They are listed from oldest to newest.

September 2008 is the previous archive.

November 2008 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle