Setting Up NetBeans IDE and Projects to Run RESTful Web Applications on Tomcat 6.0
To deploy RESTful web applications on the Tomcat 6.0 web server, you need to perform the following setup procedures:
- One-time-only setup of the IDE to support Tomcat 6.0
- Additional setup of each individual project
Setting Up the IDE (one-time-only)
- Add Tomcat server using Services tab, pointing to NetBeans 6.0 bundled Tomcat 6 installation directory.
- Copy the following files from NetBeans 6.0 installation to <Tomcat-installation>/lib
(On Windows, the toplink jars are in <Netbeans-installation>\java1\modules\ext\toplink and the derby jars are in <glassfishv2-installation>\javadb\lib)
toplink-essentials.jar
toplink-essentials-agent.jar
derbynet.jar
derbyclient.jar
- Copy all JAX-WS API jars from <NetBeans 6 installation>/java1/modules/ext/jaxws/api to <Tomcat installation>/endorsed
See
http://wiki.netbeans.org/wiki/view/FaqEndorsedDirTomcat for more details on version 5.
Configuring a Web Project
For every Web Application project you create that deploys RESTful services to Tomcat 6.0, you must perform the following additional configuration:
- Add the TopLink Essentials library to the project, above the Jersey REST libraries.
- Customize the persistence.xml file
Adding TopLink Essentials Library
Although you added Toplink files to Tomcat, you still need to add the TopLink Essentials library to your project in order to avoid class casting exceptions. You must add this library above the REST libraries.
- Right-click your project node and choose Properties from the context menu. The Project Properties dialog opens.
- In the Categories view, choose Libraries. A tab opens showing the project's compile-time libraries.
- Click Add Library. The Add Library dialog opens, showing a list of available libraries.
- Scroll through the libraries for the Top Link Essentials library. Select that library and click Add Library.
- You should now be back in the Project Properties dialog. TopLink Essentials should be listed in the Compile-time Libraries. Make sure the Package box is selected. Select TopLink Libraries and move it to the top of the list of libraries, by clicking Move Up.
- Click OK. The IDE adds TopLink Essentials to the top of the project libraries. To check that the TopLink Essentials library is there, expand the Libraries node of your project.
- Restart the IDE for your changes to take effect. After the IDE restarts, restart the Derby database server.
Customizing persistence.xml
Expand your project's Configuration Files node and you will see the persistence.xml file. Edit persistence.xml based on the following example:
<persistence-unit name="WebApplication8PU" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<!-- <non-jta-data-source>jdbc/sample</non-jta-data-source> -->
<properties>
<property name="toplink.jdbc.user" value="app"/>
<property name="toplink.jdbc.password" value="app"/>
<property name="toplink.jdbc.url" value="jdbc:derby://localhost:1527/sample"/>
<property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
</properties>
</persistence-unit>