Alexis Lopez

About Alexis Lopez

Java Lover, certified as Java Programmer, Mobile Application Developer and Web Component Developer.

Glassfish plugin for JDeveloper 11gR2

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.

Note

I had to add the –verbose option to the start command, otherwise, Glassfish starts and stops immediately.

Glassfish Home Directory: /home/aalopez/development/glassfish-3.1.2.2/

Start Glassfish Command:

/home/aalopez/development/glassfish-3.1.2.2/glassfish/bin/asadmin start-domain --verbose domain1

Stop Glassfish Command:

/home/aalopez/development/glassfish-3.1.2.2/glassfish/bin/asadmin stop-domain domain1

Start Glassfish in Debug Mode Command:

/home/aalopez/development/glassfish-3.1.2.2/glassfish/bin/asadmin start-domain --debug=true

Glassfish Admin URL:

http://localhost:4848

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:

java:comp/env/jdbc/DATASOURCE_NAME

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:

jdbc/DATASOURCE_NAME

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/WEB­INF/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.

References:

 

Reference: Glassfish plugin for JDeveloper 11gR2 from our JCG partner Alexis Lopez at the Java and ME blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


seven + 7 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close