IDEA and OpenNMS

From OpenNMS
Jump to: navigation, search

Overview

Importing the OpenNMS project into the IntelliJ IDE and make all necessary settings is the topic of this wiki site.

License

The OpenNMS development team has been granted an OpenSource License for IntelliJ's IDEA. This unfortunately means it is not free for the entire community, but yet a very valuable tool.

Availability

http://www.jetbrains.com/idea/download/index.html

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

Github1.png

  • 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 its in the users home directory. If you use OS X or Windows, the location of this directory is different. More infos you find here
  • Some of the directories in the right and left have maching directory names
  • Copy all files from right to left into the directory with the same name. Don't forget the subdirectories

Copy files.png


  • 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

Step1b.jpg


  • 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

Step2b.png


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

Step15b.png


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

Inspections.png


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

Codestyle.png

Import OpenNMS

This section describes how OpenNMS is imported into IntelliJ IDE.

  • You can now click Import Project

Step3.png


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

Step4.png


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

Step5.png


  • No changes necessary, click Next

After maven.png


  • No changes necessary, click Next

Step8b.png


  • No changes necessary, click Next

After jdk.png


  • Click the plus icon and then click JDK

Step9.png


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

Selectjdk.png


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

Step12.png


  • You can choose a project name
  • click Finish

Finish.png


  • 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 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)

Step14.png


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

Finished.png


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

Debug.png


  • Choose a name
  • Type in 8001 as port number

Port.png


Troubleshooting

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

Trouble1.png


  • 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

Trouble2.png