As some of you already know, ADF Essentials is a great framework for building web applications using java and it is free to develop and free to deploy. You deploy ADF Essentials applications on Glassfish (3.1+) server. Nevertheless, JDeveloper does not come with an embedded Glassfish server but with an embedded Weblogic server. In this post, we are going to talk about when to use the integrated Weblogic server and when you should use an external Glassfish server during your ADF Essentials application development.
What you need
Once you have installed the above software, you may start creating your ADF Essentials applications. There are tons of documentation online: books, tutorials and videos to help you. My recommendation is try to use the integrated Weblogic server during development so you can debug and run your applications right from JDeveloper. When you finish developing some functionality, test your development on Glassfish server, at the end, if you are developing an ADF Essentials applications this is the application server you are most likely to use in a production environment. Make sure you have configured your Glassfish server for ADF Essentials applications as described here:https://blogs.oracle.com/shay/entry/deploying_oracle_adf_applications_to
The version of JDeveloper you installed, comes with a built in functionality to deploy your applications to Glassfish server. However, you have to start the server before you can deploy your applications. One way to do it is to use the Glassfish server controls (they are installed once you install Glassfish) outside of JDeveloper. My recommended way is to use the Glassfish plugin for JDeveloper so you can start/stop Glassfish server right from the IDE! The plugin was created by Shay Shmeltzer and the version 1.3 has been modified to run on Linux (thx to me, @aa_lopez) and to run on Mac (thx to David Aroca).
The plugin can be found at help->check for updates. More information here: https://blogs.oracle.com/shay/entry/glassfish_extension_for_oracle_jdeveloper. If you want to make contributions to the source code, you can find the project at java.net: http://java.net/projects/jdev-3rd-party-ext/sources/svn-repository/show. Once you have installed the plugin, your JDeveloper presents four new buttons:
Form left to right:
- The first one lets you start the Glassfish server.
- The second one lets you stop Glassfish server.
- The third one starts Glassfish server in debug mode.
- The fourth one starts the Glassfish server web console app.
Before you can start using these new buttons, you have to configure the paths to the Glassfish server. To do this, go to Tools->Preferences and select the Glassfish Preferences :
The plugin comes with Windows OS paths by default. So if you are using Linux or Mac, you have to change these paths in order to have the plugin buttons working. In my case, I’m using Linux, so I changed the paths to match the paths where I installed my Glassfish server.
I had to add the –verbose option to the start command, otherwise, Glassfish starts and stops immediately.
Glassfish Home Directory: /home/aalopez/development/glassfish-184.108.40.206/
Start Glassfish Command:
/home/aalopez/development/glassfish-220.127.116.11/glassfish/bin/asadmin start-domain --verbose domain1
Stop Glassfish Command:
/home/aalopez/development/glassfish-18.104.22.168/glassfish/bin/asadmin stop-domain domain1
Start Glassfish in Debug Mode Command:
/home/aalopez/development/glassfish-22.214.171.124/glassfish/bin/asadmin start-domain --debug=true
Glassfish Admin URL:
Once you finish the configuration, you are ready to start using Glassfish server from JDeveloper, just don’t close the window that pops up when you hit the ‘Start Glassfish’ button.
How to deal with data sources between Weblogic and Glassfish servers?
When you are working with the integrated Weblogic server, JDeveloper creates a data source to access the database. This data source has the following structure:
Where DATASOURCE_NAME is the name you gave to the data source when configuring the connection to the data base. The problem is that Glassfish server uses another structure. When you define a data source in the Glassfish server web console app, you define it like this:
If you keep running your application using Weblogic and Glassfish servers, I recommend the following configuration, so you don’t have to manually change the data source structure every time you change the application server: Define the resource at Web Content/WEBINF/web.xml
<resource-ref> <res-ref-name>jdbc/DATASOURCE_NAME</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref>
As stated by the Java EE web-app deployment descriptor version 2.5:
The res-ref-name element specifies the name of a resource manager connection factory reference. The name is a JNDI name relative to the java:comp/env context. The name must be unique within a web application.
So we are not defining what to do with jdbc/DATASOURCE_NAME but we are actually defining java:comp/env/jdbc/DATASOURCE_NAME which matches exactly the data source structure configured in the application and used by Weblogic server. This is actually a good practice, since at development time you don’t have to worry about what is going to be the structure or name of the data source at deployment time. You just define, in the web.xml deployment descriptor, the structure or name of the data source and the deployer (yes, the person who makes the deployment) can map that structure or name to something else. This is done in a container-specific configuration file, as we shall see next.
Create the glassfish-web.xml configuration file. Right click on the Web Content/WEB-INF folder and select the New… option:
A window pops up, select the General category and then choose the File option:
Enter the name of the file as glassfish-web.xml and make sure the path to this new file is inside the WEB-INF folder:
Once the file is created, open it and enter the following code:
<?xml version='1.0' encoding='UTF-8' ?> <glassfish-web-app> <context-root>YOUR_APP_NAME</context-root> <property name='useBundledJsf' value='true'/> <class-loader delegate='false'/> <resource-ref> <res-ref-name>java:comp/env/jdbc/DATASOURCE_NAME</res-ref-name> <jndi-name>jdbc/DATASOURCE_NAME_AT_GLASSFISH</jndi-name> </resource-ref> </glassfish-web-app>
Here I copied the configuration that JDeveloper adds to the glassfish-web.xml file at deployment time. I also added the configuration that let us map the data sources. The resource-ref element is what we are going to focus on this post. Change DATASOURCE_NAME for the name you defined for your data source in the web.xml deployment descriptor and DATASOURCE_NAME_AT_GLASSFISH for the name you defined in the Glassfish Web console app.
How it works:
- We defined the data source as a resource in the web.xml deployment descriptor. Remember that we are using the structure jdbc/DATASOURCE_NAME but what it really means is that we are using java:comp/env/jdbc/DATASOURCE_NAME
- We created the glassfish-web.xml deployment descriptor. This is a container-specific configuration file and is created automatically by JDeveloper when you deploy to a Glassfish server. However, if the file already exists it is not overridden Here we mapped the data sources definitions so we are telling Glassfish that when we are looking for java:comp/env/jdbc/DATASOURCE_NAME in our application, what we really mean is that we are looking for jdbc/DATASOURCE_NAME in the Glassfish server.
That’s it. With this configuration you don’t have to worry about the data source configuration differences between Weblogic and Glassfish servers. Happy ADF Essentials coding.
- Oracle ADF Essentials. Oracle [online].Available on Internet: http://www.oracle.com/technetwork/developer-tools/adf/overview/adfessentials-1719844.html [accessed on March 24 2013].
- Deploying ADF Applications to GlassFish. Oracle [online].Available on Internet: http://docs.oracle.com/cd/E35521_01/web.111230/e16182/appendix_glassfish.htm#CEGDIGEE [accessed on March 28 2013].
- Java EE: XML Schemas for Java EE Deployment Descriptors. Oracle [online]. Available on Internet: http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html#5 [accessed on March 28 2013].
- What is resource-ref in web.xml used for?. Oracle [online]. Available on Internet: http://stackoverflow.com/questions/2887967/what-is-resource-ref-in-web-xml-used-for/2888169#2888169