IDE Feature, now available from the command-line

Folks that use NetBeans and GlassFish together have enjoyed the benefits of having the IDE automatically register and update resources for many years. This is one of the features that folks doing command-line based deployment have requested for many years, too. For those folks that have been waiting, I have good news. The feature is in GlassFish Server 3.1, though it is going by the name Application Scoped Resources. Jagadish provides a lot of details about application scoped resources and Alexis produced a screen cast that demonstrates application scoped resources.

After seeing all their hard work, I decided to see how I could support the feature in NetBeans.

We have been creating a file called sun-resources.xml to persist resource definitions in NetBeans for awhile. I recently made the changes necessary to start naming that file glassfish-resources.xml when a project targets GlassFish Server 3.1.

The file is currently used by the IDE to drive its automatic resource registration, if it is present in the 'Server Resources' logical folder for a project when the project is deployed. Move this file to someplace else to prevent the IDE from creating and updating resources. If you Cut the file out of the Server Resources logical folder and Paste it into

  1. the WEB-INF folder under the 'Web Pages' logical folder, you will have a Web Application project that leverages application scoped resources, OR
  2. the 'Configuration Files' logical folder, you will have an EJB Module or Enterprise Application project that leveraged application scoped resources,


Two projects, transformed to leverage application scoped resources.

The IDE doesn't do the resource registration and updates after this change. The server will when the app is deployed.

IDE features that would update the glassfish-resources.xml file will update the file in its new location after you have moved it out of the 'Server Resources' logical folder, automatically.

If you use JPA, you need to make one change to the persistence.xml file that is generated by NetBeans when you create your entity beans. You will need to change the value of the jta-data-source element. For example, if your persistence.xml says

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 
        xmlns="http://java.sun.com/xml/ns/persistence" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="EJBModule23PU" transaction-type="JTA">
    <jta-data-source>jdbc/myJDBCresource
    <properties/>
  </persistence-unit>
</persistence>
you will need to change it to say
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 
       xmlns="http://java.sun.com/xml/ns/persistence" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="EJBModule23PU" transaction-type="JTA">
    <jta-data-source>java:app/jdbc/myJDBCresource
    <properties/>
  </persistence-unit>
</persistence>

If you use JDBC directly in your code, you will need to make sure that you create a glassfish specific deployment descriptor to map the logical JDBC resource to the actual resource's JNDI name.

I have to admit, none of this would work without the hard work that Jagadish and Mitesh had to do to in the server code to get this feature working. Thanks guys. You rock.

You can start to leverage application scoped resources in modules and apps that use JPA on GlassFish Server 3.1 promoted builds 20 (and higher).

Comments:

Post a Comment:
Comments are closed for this entry.
About


Vince Kraemer writes the entries in this blog.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
News
Blogroll

No bookmarks in folder

automarks