PluginPortalWithJavaDemo

Plugin Portal with Java Demo (5 Minutes)

Description

This demo uses the Java FreeTTS speech synthesizer to read our plugin's fields.

Product Versions Supported

NetBeans 6.0 M10

Points to Hit

  • With JRuby can you take advantage of the agility of developing in Rails while continuing to leverage your existing investment in Java.

Demo Prep

  1. This demo is a follow-on to the Agile Development Of The Plugin Portal demo, so complete that demo first.
  2. Download and extract FreeTTS. Only the binaries are needed.
  3. Copy the jars from the FreeTTS lib directory to your JRuby lib directory

Gotchas

None. This demo runs like a sled on gravel.

Demo

Switch to the JRuby interpreter

  • Switch to the JRuby interpreter.
  • On UNIX, you'll also need to update the database.yml, replacing socket with host as follows (note, this configuration also works with CRuby. I can only guess it's not used as the default configuration because of performance):
development:
  adapter: mysql
  database: plugin_portal_development
  username: root
  password:
  #socket: /tmp/mysql.sock
  host: localhost
  • Run the appliation on JRuby, unmodified except for the database configuration change.

Review the setup

Explain that the required jars were copied to your JRuby lib directory

Create a hyperlink to speak the associated field text

  1. Open show.rhrml in insert a blank line before the closing </p>.
  2. Type liai<Tab> to expand the LInk Action Index template. Set the arguments so that the resulting link looks as follows:
 <%= link_to "Speak", :action => "speak", :id => @plugin.send(column.name) %>

Code the speak action

  • Press Ctrl+Shift+A to navigate to the controller.
  • At the top of the file (before the class definition) type jc<Tab> to expand the require 'java' template. Complete the code as follows:
  require 'java'
  include_class 'com.sun.speech.freetts.Voice'
  include_class 'com.sun.speech.freetts.VoiceManager'
  • Define the speak action as follows:
  def speak
    # Get a voice
    voice = VoiceManager.getInstance.getVoice('kevin16')
    # Allocate a resource for the voice
    voice.allocate
    voice.speak(params[:id])
    redirect_to :back   
  end
  • Place you cursor in the index or list method and press Shift+F6 to launch the index page and test the results.

See what happens in native Ruby land

Switch back to the native interpreter. "no such file to load -- java"
Sorry.

Demo Cleanup

These are the necessary steps to take in order to successfully run the demo again on the same machine.

  • Delete the plugin_portal project
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