Setting up IntelliJ IDEA for OpenNMS development

IntelliJ IDEA can be downloaded as a free community or with a paid license as Ultimate edition with a larger feature set for Linux, Windows, and macOS. It is a popular IDE and a lot of full-time developers in the OpenNMS community leverage from the great feature set.

Using IDEA

Build OpenNMS

  • OpenNMS has to be build from command line first before its imported into IntelliJ
  • Open a terminal window
  • Check out the source as normal
  • Change to the root directory of the OpenNMS project
  • On the command line execute
./clean.pl && ./compile.pl -DskipTests && ./assemble.pl -p dir

IntelliJ settings

These settings are necessary to be consistent with eclipse created files for classes and interfaces

  • In your browser navigate to this git repository and download the .zip

  • Unzip the .zip and you will see a directory structure as in the screenshot right below
  • On the left screenshot below you see the directory used by the IntelliJ IDE to store settings, caches, plugins, and logs
  • In the case of Linux it’s in the user’s home directory. If you use OS X or Windows, the location of this directory is different. More info you find in here.
  • Some of the directories in the right and left have matching directory names
  • Copy all files from right to left into the directory with the same name. Don’t forget the subdirectories

  • You should have copied these files from right to left:
/ide-setup/intellij/codestyles/opennms.xml
/ide-setup/intellij/fileTemplates/includes/File Header.java
/ide-setup/intellij/fileTemplates/includes/File Licence.java
/ide-setup/intellij/fileTemplates/internal/AnnotationType.java
/ide-setup/intellij/fileTemplates/internal/Class.java
/ide-setup/intellij/fileTemplates/internal/Enum.java
/ide-setup/intellij/fileTemplates/internal/Interface.java
/ide-setup/intellij/fileTemplates/internal/package-info.java
/ide-setup/intellij/inspection/opennms.xml
  • Start IntelliJ and the welcome dialog will open
  • Navigate to Configure -> Settings

  • On the left side click Build, Execution, Deployment -> Build Tools -> Maven -> Importing
  • Here you have to make 2 changes, which are not by default
  • Check `Import Maven projects automatically
  • In the input field VM options for importer type in the value -Xmx4096m
  • Click Apply

  • Navigate to File -> Settings -> Editor -> General -> Autoimport
  • Check Optimize imports on the fly
  • Click Apply

  • Navigate to Editor -> Inspections
  • On the right is a drop-down called Profile. There select opennms
  • Confirm that anything related to osgi is unchecked
  • :tipping_hand_woman:t4: The community version doesn’t provide OSGi features!
  • Click Apply

  • Navigate to Editor -> Code Style
  • On the right is a drop-down called Scheme. There select opennms
  • Click Apply and OK

Import OpenNMS

This section describes how OpenNMS is imported into IntelliJ IDE.

  • You can now click Import Project

Step3

  • Navigate to the directory where OpenNMS was cloned to mark it and click OK

  • Enable the option Import projects from external model and mark Maven in the list below
  • Click Next

  • No changes necessary, click Next

  • Please make sure, that the following profiles are selected:

    • assemblies
    • jdk7+
    • smoke
  • Afterwards, click Next

  • No changes necessary, click Next

  • Click the plus icon and then click JDK

  • Navigate to the Java jdk root directory (it must be Oracle Java, ‘’‘not’’’ OpenJDK)
  • Mark it and click OK

  • The result is a classpath set with jar files like in the screenshot below
  • Click Next

  • You can choose a project name
  • click Finish

  • This is now the main screen of Intellij
  • You may see warnings on the top right
  • One is about inotify optimization. Please click the related link in the IDE for further information.
  • One is about Unregistered VCS root detected. You can click Add root to link the root of the project to your local git repository.
  • If you click on the process running in the status bar you can see the progress of maven tasks (this can last 10-30 min depending on internet connection and hardware)

  • When all is finished you see the OpenNMS project structure imported

IntelliJ Debugging

  • OpenNMS has to be started with debug mode options
./bin/opennms -vt start
  • Navigate to Run -> Edit configurations...
  • Press the green plus icon and select Remote

  • Choose a name
  • Type in 8001 as port number

Performance Improvement

Change IDEA Settings

  • Open Help -> Edit Custom VM Options...
  • Change the following lines
-Xms256m
-Xmx1536m
-XX:ReservedCodeCacheSize=480m
  • restart IntelliJ

Change OS Settings

Linux only:

Troubleshooting

Error: Project SDK or Error: Project language level

You may get an error regarding Project SDK or Project language level. In that case do settings settings below

  • Right click on project root and click Open Module Settings

  • Navigate to Project Settings -> Project
  • For Project SDK select Java 1.8
  • For Project language level selet 8 - Lambdas, type annotations. etc.
  • Click OK

OpenNMS has been successfully imported into the IntelliJ IDE now

Error: osgi: [opennms-osgi-core] Manifest file ‘-osgi.bnd’ missing - please check OSGi facet settings.

At the bottom of the Run/Debug Configurations screen in the Before launch section, remove Build and add Build, no error check. See this for details: java - Enable Partial Compilation in IntelliJ IDEA - Stack Overflow


:woman_facepalming: You can fix me, I’m a wiki post.