Last reviewed: 3/23/2024 8:18:12 AM

Java Applications

Develop Java applications that manage grammars using your favorite Java development tools. This includes development environments such as Eclipse, IntelliJ, JDeveloper, and NetBeans.

The following sections describe the steps for integrating GrammarKit with Java applications.

JRE Configuration

GrammarKit includes Java libraries for JDK 1.8, 11, 17, and 21 to support most application's target runtime environments. If you need a specific target runtime, then contact Chant Product Support.

To access the GrammarKit Java classes within your application, add the class libraries to your JDK environment:

  1. copy the JGrammarKit.DLL file to your Java JDK bin directory;
  2. copy the applicable 32-bit speech API DLL file(s) to your Java JDK bin directory;
  3. copy the grammarkit.jar and chant.shared.jar libraries to your Java JDK lib; and
  4. append a path reference for your Java JDK lib\grammarkit.jar and lib\chant.shared.jar paths as a classpath property in your system settings.
  1. copy the JGrammarKitX64.DLL file to your Java JDK bin directory;
  2. copy the applicable 64-bit speech API DLL file(s) to your Java JDK bin directory;
  3. copy the grammarkit.jar and chant.shared.jar class libraries to your Java JDK lib; and
  4. append a path reference for your Java JDK lib\grammarkit.jar and lib\chant.shared.jar paths as a classpath property in your system settings.

To access the GrammarKit Java classes within your application, add references to the Chant shared and GrammarKit class libraries in your code:


import com.grammarkit.*;
import net.chant.shared.*;

Object Instantiation

Declare a global variable for the GrammarKit class, instantiate an instance, set the credentials, and set the event handler.


public class Frame1 extends JFrame implements com.grammarkit.JChantGrammarKitEvents
{
    private JGrammarKit _GrammarKit = null;
    private JSAPI5Recognizer _Recognizer = null;

    private void jInit() throws Exception
    {
        // Create GrammarKit object
        if (_GrammarKit != null)
        {
            _GrammarKit = new JGrammarKit();
            // Set credentials
            _GrammarKit.setCredentials("Credentials");

            _Recognizer = _GrammarKit.createSAPI5Recognizer();
            if (_Recognizer != null)
            {
                // Set the callback object
                _Recognizer.setChantGrammarKitEvents(this);
                // Register for callbacks
                _Recognizer.registerCallback(ChantGrammarKitCallback.CCGMDone);
                _Recognizer.registerCallback(ChantGrammarKitCallback.CCGMError);
            }
        }
    }
}

GrammarKit Java applications require the grammarkit.jar and chant.shared.jar in the target system Java JRE lib directory and/or ensure the classpath includes the path where the grammarkit.jar and chant.shared.jar libraries are placed on your target system. The GrammarKit library (JGrammarKit.dll or JGrammarKitX64.dll) and the applicable GrammarKit Speech API library must be in the target system Java JRE bin directory.

Speech API GrammarKit Speech API class GrammarKit Speech API library
Microsoft SAPI 5JSAPI5RecognizerCGrammarKit.SAPI5.dll or CGrammarKitX64.SAPI5.dll
Microsoft Speech PlatformJMSPRecognizerCGrammarKit.MSP.dll or CGrammarKitX64.MSP.dll
Microsoft WindowsMediaJWindowsMediaRecognizerCGrammarKit.WinRT.dll or CGrammarKitX64.WinRT.dll

Event Callbacks

Event callbacks are the mechanism in which the class object sends information back to the application such as compilation is complete or there was an error.


// Event Handlers
public void apiError(Object sender, ChantAPIErrorEventArgs args)
{
    // Optional check for API errors
}
public void compileDone(Object sender, CompileEventArgs args)
{
    ...
}
public void compileError(Object sender, CompileEventArgs args)
{
    // Format transcript message
    String errorMsg = "";
    errorMsg = "(" + args.getError() + ") ";
    errorMsg = errorMsg + "error " + args.getLineNumber() + " ";
    errorMsg = errorMsg + args.getDescription() + "\r\n";
    ...
}

Development and Deployment Checklist

When developing and deploying Java applications, ensure you have a valid license, bundle the correct Chant class libraries, and configure your installation properly on the target system. Review the following checklist before developing and deploying your applications:

  • Develop and deploy Java applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
  • Copy grammarkit.jar and chant.shared.jar to the target system Java JRE lib directory and/or ensure the classpath includes the path where the grammarkit.jar and chant.shared.jar libraries are placed on your target system.
  • Copy JGrammarKit.dll to the target system Java JRE bin directory.
  • Copy applicable 32-bit GrammarKit Speech API DLL(s) to the target system Java JRE bin directory.
  • Develop and deploy Java applications to any system with a valid license from Chant. See the section License for more information about licensing Chant software.
  • Copy grammarkit.jar and chant.shared.jar to the target system Java JRE lib directory and/or ensure the classpath includes the path where the grammarkit.jar and chant.shared.jar libraries are placed on your target system.
  • Copy JGrammarKitX64.dll to the target system.
  • Copy applicable 64-bit GrammarKit Speech API DLL(s) to the target system Java JRE bin directory.

Sample Projects

Java sample projects are installed at the following location:

  • Documents\Chant\GrammarKit 10\Java.