Skip to content

Setup IntelliJ for development of Knora

Create an IntelliJ Project for Knora

  • Download and install IntelliJ IDEA.
  • Follow the installation procedure and install the Scala plugin

screenshot 'Install Scala Plugin'

  • Add Bazel Plugin and Project to IntelliJ
  • The latest version of the Bazel plugin supports only IntelliJ upto version 2019.03.05. After you make sure to run this version of IntelliJ, install the plugin from inside IntelliJ.
  • Click on File -> Import Bazel Project and select twice next.
  • Uncomment the Scala language and click Finish.

  • make sure that the tab size is set correctly to 4 spaces (so you can use automatic code reformatting): Preferences -> Code Style -> Scala:

screenshot 'setting tab size'

Use IntelliJ IDEA's Debugger with Knora

  • Create an application configuration:

screenshot 'edit application config'

screenshot 'create application configuration'

Fill in the configuration details:

screenshot 'change application configuration'

  • Click on the debugging symbol to start the application with a debugger attached:

screenshot 'debug'

  • Click on a line-number to add a breakpoint

screenshot 'set a breakpoint'

Use a Remote Debugger with Intellij

  • edit configurations (Run -> Edit Configurations...)
  • add a new remote configuration:

screenshot 'remote configuration'

  • from the console (in folder webapi), run sbt -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
  • start Knora using reStart
  • use debugger: choose configuration and click on Debug [configName]

screenshot 'use debugger'

Profile Knora Using VisualVM in IntelliJ

First, download and install VisualVM.

Then, in IntelliJ, under Preferences -> Plugins, search for the VisualVM Launcher, click on "Search in repositories", install the plugin, and restart IntelliJ. IntelliJ's toolbar should now contain a button with a green triangle on an orange circle, with the tooltip "Run with VisualVM":

screenshot 'Run with VisualVM button'

You can use this button to run the class org.knora.webapi.app.Main and profile it in VisualVM. The first time you do this, IntelliJ will ask you for the path to the VisualVM executable. On macOS this is /Applications/VisualVM.app/Contents/MacOS/visualvm.

When VisualVM starts, it will open a window like this:

screenshot 'VisualVM overview'

To use the profiler, click on the "Sampler" tab, then on the "CPU" button:

screenshot 'VisualVM sampler'

Now run some Knora API operations that you're interested in profiling, preferably several times to allow the sampler to collect enough data. Then click on the "Snapshot" button:

screenshot 'VisualVM snapshot
button'

In the snapshot, you'll see a list of threads that were profiled:

screenshot 'VisualVM snapshot'

You can then browse the call tree for each thread, looking for Knora method calls, to see the total time spent in each method:

screenshot 'VisualVM call tree'