STK Java API - Configuring the Samples with the Eclipse IDE

On windows the code samples included in the STK install are read only. To work with any of the installed code samples:

  1. From the Windows Start menu, select STK 12->STK Codesamples 12 to access <STK install folder>/CodeSamples/CodeSamples.zip.
  2. Copy CodeSamples.zip to a folder where you have write permissions and unzip the file.
  3. Change the properties of the files to writable before compiling them.
  4. Use the directory you chose instead of <STK install folder>\CodeSamples in the following instructions.

The following instructions explain how to configure the STK Java API code samples provided in the STK install within the Eclipse Integrated Development Environment (IDE).

  1. Refer to the getting/installing Eclipse if you do not already have Eclipse installed on your machine. DO NOT create a new Eclipse Java application project.
  2. Start up the Eclipse IDE.
  3. When asked to select a Workspace, browse to the <STK install folder>\CodeSamples directory. Where <STK install folder> is the current release installation of STK / STK Engine.
  4. Click the OK button.

    If the Eclipse IDE launches without displaying the above dialog, open the File menu and select Switch Workspace to display it, then browse to the above directory.

  5. Close the Eclipse IDE's Welcome screen.
  6. In Eclipse, left-click on the Window menu bar item.
  7. Left-click on the Preferences menu item.
  8. In the Preferences dialog, choose General -> Workspace -> Linked Resources.
  9. Left-click on the New... button.
  10. In the New Variable dialog, type JavaDevKit in the Name text field.
  11. Next left-click the Folder... button and in the folder selection dialog select your <STK install folder>/bin folder and click the OK button.
  12. To set-up the SWT samples:
    1. Left-click on the New... button.
    2. Name this variable SwtJar and left-click on the File... button.
    3. Browse to <Eclipse Install Folder>/plugins folder and select the org.eclipse.swt.win32.win32.x86_64_<version>.jar for windows or org.eclipse.swt.gtk.linux.x86_64_<version>.jar for linux.
  13. From the File menu, select Import...
  14. In the Import dialog, open the General folder.
  15. Select Existing Projects into Workspace.
  16. Click the Next button.

  17. Choose Select root directory.
  18. Click the Browse button.
  19. Do NOT change the directory; instead, just click the OK button to dismiss the Browse for Folder dialog.

  20. Make certain that the projects shown in the image below are selected in the Projects area.

  21. Click the Finish button.
  22. By default most of the samples are pre-configured out of the box to begin to compile and start if STK was installed to the default location/settings and you have set up the workspace resources.
  23. Note that CustomApp_AWT_STK_Objects_DataProviders_HowTo project will not compile. The errors in CustomApp_AWT_STK_Objects_DataProviders_HowTo samples are because additional steps are required for their set-up.
  24. CustomApp_AWT_STK_Objects_DataProviders_HowTo require jfreechart to build. You can find this project at www.jfree.org/jfreechart. Get or compile the jfreechart jar file and add it as an external jar file to the projects to get them to build.
  25. If you see any Samples with compilation error icons, check the following:
  26. If the errors are in all of the projects then check that the JavaDevKit Linked Resource is set to the correct directory.

    If the errors are only in the SWT projects then check that the SwtJar Linked Resource is set to the correct file.

    Open each project's properties and verify the Java Build Path does not have any unresolved errors.

  27. Click the Libraries tab, and note the jar libraries have a javadoc location are set to the default javadocs library. If not set properly, follow the steps in configuring an Eclipse project with the STK Java API javadoc intellisense.
  28. Some of the following steps may require editing of the project's Properties. Before performing such editing, you may want to make sure that the file is writable. See the section on Saving Project Settings at the end of this page.

  29. If you have changed any settings on the Properties page, click OK to save the settings and dismiss the page.
  30. Check to see if the samples have already been compiled. The Eclipse IDE automatically compiles Java files when they are added or changed within a project. Open the Project menu and see whether a check mark appears next to the Build Automatically item. If so, the samples have been compiled, and you can skip the next step.
  31. If the samples have not yet been compiled, then right-click on the current project you are working with in the Package Explorer and select Build Project.

Set .classpath file to writable if necessary for saving project settings

To make certain that you will be able to save any changes you make to the project's Properties page, find the .classpath file for the Eclipse project and verify that they are writable.

If you do not see the .classpath file in the Eclipse project directory...

  1. On Windows ...
    • Open Windows Explorer.
    • Hit the alt key on the keyboard.
    • Select Folder Options from the Tools menu.
    • Click the View tab.
    • Select the "Show hidden files and folders" option.
  2. On Linux ...
    • Open a terminal window.
    • Browse to the folder containing the .classpath file.
    • Run the command: ls -a