This section describes how to install and setup JetBrains' IntelliJ IDEA, then how to import an application into IntelliJ and run it.
|This material does not constitute an endorsement; JetBrains is not affiliated to Apache Software Foundation in any way. JetBrains does however provide complimentary copies of the IntelliJ IDE to Apache committers.|
This section covers installation and setup. These notes/screenshots were prepared using IntelliJ IDEA Community Edition 2019.3, but is believed to be compatible with more recent versions/other editions of the IDE.
Download latest version of IntelliJ Community Edition, and install.
In IntelliJ a project can contain multiple modules; these need not be physically located together.
From the welcome screen, select "import project":
Navigate to the top-level pom.xml of the starter app:
Start off by creating a new project:
Useto confirm that JDK 8 is configured:
There are a number of compiler settings that influence the compiler. We highly recommend you set these.
On the Compiler Settings page, ensure that
build automatically is enabled (and optionally
compile independent modules in parallel):
On the Annotation Processors page, confirm that these are enabled for all of the
packaging=jar modules (in other words, those that contain Java and have a
If using JDO/DataNucleus, this setting enables the generation of the
Q* classes for DataNucleus type-safe queries.
It is also required for frameworks such as Lombok.
There are also some other settings for Maven that we recommend you adjust (though these are less critical):
On the Maven settings page:
Still on the Maven settings page, configure as follows:
On the Auto Import settings page, check the
optimize imports on the fly and
add unambiguous imports on the fly
You might also want to exclude certain packages or classes from auto-import, for example:
You might want to set up some additional plugins.
You can do this using
File > Settings > Plugins (or equivalently
File > Other Settings > Configure Plugins).
Highly recommended are:
Let’s see how to run both the app and the tests.
We run the application by creating a Run configuration, using
Run > Edit Configurations.
With JPA, the classes need to be "weaved" in order to support lazy loading and (more performant) dirty object tracking.
This is typically done dynamically at runtime, using a Java agent.
The SimpleApp and HelloWorld starter apps demonstrate this, bundling the
To run, use:
as a JVM argument (where the system properties also are located.)
DataNucleus requires that all entities are bytecode enhanced.
When building from the command line using Maven, the
datanucleus:enhance Maven plugin takes care of this.
We can just have IntelliJ run the enhance as a separate run configuration before the run configuration that runs the app itself.
First, set up the run configuration to do the enhance:
|Check "work offline" (on the General tab) to speed this up slightly.|
If on Windows you encounter a "The command line is too long" error, then set '-Dfork=false' as a VM option (on the Runner tab).
Then, set up the run configuration for the app. Note how it runs the enhance configuration first:
You should now be able to run the app using
Run > Run Configuration.
The same configuration can also be used to debug the app if you so need.
The easiest way to run the unit tests is just to right click on the relevant package in the Project Window, and choose run unit tests. Hopefully your tests will pass (!).
As a side-effect, this will create a run configuration, very similar to the one we manually created for the main app:
Thereafter, you should run units by selecting this configuration (if you use the right click approach you’ll end up with lots of run configurations, all similar).
Integration tests can be run in the same way as unit tests.
One approach is to initially run the tests use the right click on the
If the app uses JDO, then the tests might fail because the entities won’t have been enhanced. However, we can then easily update the run configuration to run the datanucleus enhancer goal (same as when running the application):
Make sure that the