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:
- From the Windows Start menu, select STK 12->STK Codesamples 12 to access <STK install folder>/CodeSamples/CodeSamples.zip.
- Copy CodeSamples.zip to a folder where you have write permissions and unzip the file.
- Change the properties of the files to writable before compiling them.
- 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).
- 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.
- Start up the Eclipse IDE.
- 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. - 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.
- Close the Eclipse IDE's Welcome screen.
- In Eclipse, left-click on the Window menu bar item.
- Left-click on the Preferences menu item.
- In the Preferences dialog, choose General -> Workspace -> Linked Resources.
- Left-click on the New... button.
- In the New Variable dialog, type JavaDevKit in the Name text field.
- Next left-click the Folder... button and in the folder selection dialog select your <STK install folder>/bin folder and click the OK button.
- To set-up the SWT samples:
- Left-click on the New... button.
- Name this variable SwtJar and left-click on the File... button.
- 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.
- From the File menu, select Import...
- In the Import dialog, open the General folder.
- Select Existing Projects into Workspace.
- Click the Next button.
- Choose Select root directory.
- Click the Browse button.
- Do NOT change the directory; instead, just click the OK button to dismiss the Browse for Folder dialog.
- Make certain that the projects shown in the image below are selected in the Projects area.
- Click the Finish button.
- 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.
- 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.
- 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.
- If you see any Samples with compilation error icons, check the following:
- 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.
- If you have changed any settings on the Properties page, click OK to save the settings and dismiss the page.
- 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.
- 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.
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.
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.
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...
- 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.
- On Linux ...
- Open a terminal window.
- Browse to the folder containing the .classpath file.
- Run the command: ls -a