DeployREST2Tomcat55

Setting Up NetBeans IDE to Run RESTful Web Applications on Tomcat 6.0

To deploy RESTful web applications on the Tomcat 6.0 web server with NetBeans IDE , you need to perform the following setup procedures:

Procedure Version of NetBeans IDE
One-time-only setup of Tomcat 6.0 to support the IDE All versions. Not all steps necessary with NetBeans 6.5 and higher.
Additional setup of each individual project Only versions before 6.5
Modify applicationContext.xml Only for NetBeans IDE 6.5 Beta, and only if you want to create RESTful web services with the Spring framework


Setting Up Tomcat 6.0

  • Add Tomcat server to NetBeans IDE using Services tab, pointing to NetBeans bundled Tomcat 6 installation directory.
  • Copy the following files from the NetBeans installation to <Tomcat-installation>/lib. Note that in version 6.5+, it is not necessary to copy the toplink jars.

(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  (for NB version < 6.5)
    toplink-essentials-agent.jar (for NB version < 6.5)
    derbynet.jar (all versions NB)
    derbyclient.jar (all versions NB)


See http://wiki.netbeans.org/wiki/view/FaqEndorsedDirTomcat for more details on version 5.

Configuring The Web Project

In versions of the IDE prior to 6.5, 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.

  1. Right-click your project node and choose Properties from the context menu. The Project Properties dialog opens.
  2. In the Categories view, choose Libraries. A tab opens showing the project's compile-time libraries.
  3. Click Add Library. The Add Library dialog opens, showing a list of available libraries.
  4. Scroll through the libraries for the Top Link Essentials library. Select that library and click Add Library.
  5. 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.
  6. 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.
  7. 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> -->
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <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>

</bean> <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">

   <property name="entityManagerFactory" ref="entityManagerFactory"/>

</bean>

</pre>

Note that the user also needs to replace YourPUName with the PU name from the original bean definition for entityManagerFactory.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo