IntelliJ IDEA

Once you have checked out the project as described in How to build SNAP from sources you can configure IntelliJ IDEA.

Importing source code as a Project

  • Select from the menu File/New/Project from Existing Sources or if you're on the Welcome Screen choose Import Project.
  • Find the checkout directory of snap-engine. Keep the default values for all settings in the upcoming dialog. Just make sure that you select the option Import project from external model and that Maven is selected as the external model.
  • Next, select from the menu File/New/Module from Existing Sources and select the snap-desktop folder. Keep again the default values.
  • Repeat the last step for the other project you might have checked out.
  • Open File/Project Structure. Ensure that as SDK a Java 11 version is selected and for Language level select the option 11 - Local variable syntax for lambda parameters. Confirm the changes.
  • On the right side of the IDE you find the Maven Projects tab. There you can invoke the Maven commands to build the project. You should configure this window by clicking on the three-vertical-dots symbol and selecting Group Modules.

Launching and Debugging

In order to launch and debug SNAP you need to create a run configuration. Before doing so you first need to build the project via maven. You can either do this from the command line or from the Maven window in Intellij IDEA. You simply need to invoke mvn package for each of the projects you have checked out. This is necessary to have the target directories available which will be referenced in the run configuration.

Run plain SNAP Desktop

Select Run/Edit Configurations and add a new configuration named Application.
In the following <snap-app> is an abbreviation for <myprojects>/snap/snap-desktop/snap-application/target/snap:

  • Main class: org.esa.snap.nbexec.Launcher
  • VM options:  -Dsun.java2d.noddraw=true -Dsun.awt.nopixfmt=true -Dsun.java2d.dpiaware=false -Dorg.netbeans.level=INFO -Dsnap.debug=true -Xmx4G
  • Program arguments:  --userdir "<snap-app>/../userdir" --patches "<myprojects>/snap/snap-engine/$/target/classes"
  • Working directory<snap-app>
  • Use classpath of module: snap-main

Note that in the configuration above, the SNAP user directory at <snap-app>/../userdir will be deleted after each clean build. This is by intention. If you want to keep your settings during development (not recommended), you can configure the SNAP user directory to any other location outside of the target directory.

The '$' character in the patches path is a place holder for all the sub-modules in this project.

you can add the --open option to the program arguments to specify one more paths to products which shall be opened on start up. Also a session file is possible.

Run SNAP Desktop with additional Toolboxes (microwave, optical, smos, ...)

If you want to use one or more toolboxes with SNAP Desktop you need to do the following. You can use the previous configuration as template by copying it.

Note that you can add multiple run configurations. One for plain SNAP Desktop, one with s1tbx, one with smos, one with s2tbx and s3tbx, and other combinations. This gives you the flixbility to run SNAP in different configurations.

For Unix-users: In the following the ';' character is use to separate the paths. That's the seperator for Windows. On Unix based system you should use ':' instead,

Extend the --patches option to include the compile output of the toolboxes.

--patches "<myprojects>/snap/snap-engine/$/target/classes;<myprojects>/snap/microwave-toolbox/$/target/classes;<myprojects>/snap/microwave-toolbox/rstb/$/target/classes;<myprojects>/snap/microwave-toolbox/jlinda/$/target/classes;<myprojects>/snap/optical-toolbox/$/target/classes"

Additionally the --clusters option needs to be set. The clusters contain all modules of a toolbox and are located in the so called kit module of each of them.

--clusters "<myprojects>/snap/microwave-toolbox/microwavetbx-kit/target/netbeans_clusters/microwavetbx;<myprojects>/snap/microwave-toolbox/microwavetbx-kit/target/netbeans_clusters/rstb;<myprojects>/snap/optical-toolbox/opttbx-kit/target/netbeans_clusters/opttbx"

Run gpt

In order to run gpt directly from the IntelliJ IDEA you should use the following configuration.

  • Main class: org.esa.snap.runtime.Launcher
  • VM options: -Dsnap.mainClass=org.esa.snap.core.gpf.main.GPT -Dsnap.home="<myprojects>/snap/snap-desktop/snap-application/target/snap" -Dsnap.extraClusters="<myprojects>/snap/microwave-toolbox/microwavetbx-kit/target/netbeans_clusters/microwavetbx;<myprojects>/snap/microwave-toolbox/microwavetbx-kit/target/netbeans_clusters/rstb;<myprojects>/snap/optical-toolbox/opttbx-kit/target/netbeans_clusters/opttbx" -Dsnap.debug=true -Xmx10G
  • Program arguments:  -h
  • Working directory<snap-app>
  • Use classpath of module: snap-runtime

As Program arguments you can specify the arguments you usually use with gpt. If you have enough memory available you can increase the value for the Xmx option. This value defines how much memory SNAP can use. Make sure that you leave some spare memory for the OS and other applications.