In this tutorial, you will learn how to successfully run the LuciadLightspeed samples from IntelliJ IDEA.

Prerequisites for the IDE integration

In the project configuration procedure, it is assumed that you already installed the following software:

Creating a LuciadLightspeed development project in IntelliJ

  1. Start IntelliJ and create a new project: either click New Project on the Welcome screen, or go to File > New > Project from the main menu. The New Project screen opens.

    WelcomeNewProject
  2. Select Java in the left-hand pane, select the installed JDK from the Project SDK drop-down menu, and click Next.

    newproject2

    If your JDK is not in the Project SDK dropdown menu, you can add it. Click Add JDK from the dropdown menu, locate the JDK in your file system, and click OK.

  3. In the next New Project screen, leave the Create project from template check box de-selected, and click Next.

  4. Select the LuciadLightspeed installation directory in the Project location field, C:\Installs\LuciadLightspeed_2018.0 for example. The project name is filled in automatically.

    newproject3
  5. Click Finish to close the project creation wizard.

    IntelliJ sets up your project, and starts indexing all the project files. This may take a few minutes but there is no need to wait. You can continue with the configuration of your project while IntelliJ continues indexing. You can look at the structure of your new project in the project navigation pane on the left.

    At some point, IntelliJ may notify you that it detected OSGi and Web frameworks, and offer you the option to configure those frameworks. Click the Configure link, and de-select both frameworks in the Setup Frameworks dialog. Configuring the framework setup to include the frameworks may result in a broken project.

Completing the project configuration

Before you can run the samples, you need to make sure that all project dependencies are in place, such as the LuciadLightspeed license file and the project resources. It is also strongly recommended to enable annotation processing in your project. LuciadLightspeed uses annotations to register services with a registry, and provide instant application services.

  1. In the project navigation pane on the left, right-click the LuciadLightspeed_<version>\src directory, and select Mark directory as > Unmark as Sources Root.

    IntelliJ creates the src directory by default. We have no use for it as a source root directory, so we unmark it as such. You can also choose to just delete the directory.

    unmarkasroot
  2. Right-click the LuciadLightspeed_<version>\samples\src directory, and select Mark directory as > Sources Root.

    markasroot
  3. From the main menu, go to File > Project Structure > Modules > Dependencies to add required files and directories.

  4. Click the + icon, and select the JARs or directories…​ option. In the next dialog, select one of the following files and directories, and click OK:

    • development license file development.jar. This file typically resides in the licenses folder.

    • lib directory

    • samples/lib/thirdparty directory. This directory contains all the third-party libraries used in the samples. See the prerequisites page for a full list.

    • config directory

    • samples/resources directory

      In the Choose Categories of Selected Files dialog, select Classes, and click OK. Repeat this step until you have added each file and directory in the list.

      addmoduledependencies
      moduledependenciesdone
  5. Still in the Project Structure window, go to Project, and change your project language level to Java 8 at least. This setting defines the minimum Java version that your applications require to run.

    setprojectlanguagelevel
  6. Click Apply > OK to close the Project Structure window.

  7. Go to File > Settings > Build, Execution, Deployment > Compiler > Annotation Processors, and select the Enable Annotation processing check box.

    Click OK to finish the project configuration.

    If you are running IntelliJ on MacOS, you need to go to IntelliJ IDEA > Preferences > Build, Execution, Deployment > Compiler > Annotation Processors.

    annotationprocessing

Defining a run configuration for the LuciadLightspeed samples

Luciad strongly recommends specifying a number of Virtual Machine (VM) options before running your samples. They will ensure that your samples run smoothly, and perform well. You can specify the VM options in the run configuration for your LuciadLightspeed project.

  1. Go to Run > Edit Configurations…​

  2. In the Run/Debug Configurations window, click Edit configuration templates…​ in the left-hand pane.

  3. In the Run/Debug Configuration Templates window, select Application from the left-hand pane.

  4. In the Build and run section, select the appropriate JDK.

  5. In the Modify options drop-down menu, select Add VM options.

  6. Copy the VM options below into the VM options field, and click OK.

    -Xmx1500m
    -Djava.net.useSystemProxies=true
    -Djava.util.logging.config.file=samples/resources/samples/logging.properties
    -Dsun.awt.noerasebackground=true
    -Dsun.java2d.opengl=false
    -Dswing.aatext=true
    -Dsun.java2d.d3d=false
    -Djava.library.path=
    --add-exports java.desktop/sun.awt.image=ALL-UNNAMED
    --add-exports java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED

    If you want to run JavaFX samples on Java 11 or higher, and you installed a JavaFX SDK separately from your project JDK, also specify these VM options:

    --add-modules javafx.controls,javafx.web,javafx.swing,javafx.fxml
    --module-path /path/to/your/javafx-sdk/lib
    vmoptionsrunconfiguration
  7. Click Apply > OK, and click OK again to close the Run/Debug Configurations window.
    From now on, your samples will use the specified VM options when you run them.

Integrating the LuciadLightspeed Javadoc into your project

IntelliJ can show you the Javadoc for a LuciadLightspeed API code element when you select the code element and press Ctrl+Q. To activate this Quick Documentation feature for the LuciadLightspeed Javadoc:

  1. From the main menu, go to File > Project Structure > Modules > Dependencies.

  2. Right-click the LuciadLightspeed_<version>\lib entry, and select Edit…​ from the context menu.

    addingjavadoc
  3. In the Configure Module Library window, click the + Add button.

  4. Navigate to the docs/reference/LuciadLightspeed folder, select it, and click OK.

  5. Click OK twice more to close the Configure Module library window, and the Project Structure window.

You are done! Now you can run the sample of your choice and start developing.

Test running a sample

In the samples/src directory, you can run the sample executable files with the intellij run icon icon. Note the green "Play" symbol in the icon.

You can test your IDE setup by running the shapes example:

  1. Expand the samples\src\samples\lightspeed\shapes folder in the project navigation pane on the left.

  2. Right-click on MainPanel and select Run MainPanel.main() from the context menu. The sample starts in this window.

    runningsample

You can now look at the code, modify it, or start developing your own application.

If IntelliJ is still busy indexing the project files you will have to wait until it finishes before you are able to run the samples.