2.3 Setting up an IDE
The application created in the previous section contains a “main class” located in src/main/java
that looks like the following:
import io.micronaut.runtime.Micronaut;
public class Application {
public static void main(String[] args) {
Micronaut.run(Application.class);
}
}
import io.micronaut.runtime.Micronaut
class Application {
static void main(String... args) {
Micronaut.run Application.class
}
}
import io.micronaut.runtime.Micronaut
object Application {
@JvmStatic
fun main(args: Array<String>) {
Micronaut.run(Application.javaClass)
}
}
This is the class that is run when running the application via Gradle or via deployment. You can also run the main class directly within your IDE if it is configured correctly.
Configuring IntelliJ IDEA
To import a Micronaut project into IntelliJ IDEA simply open the build.gradle
or pom.xml
file and follow the instructions to import the project.
For IntelliJ IDEA if you plan to use the IntelliJ compiler then you should enable annotation processing under the “Build, Execution, Deployment → Compiler → Annotation Processors” by ticking the “Enable annotation processing” checkbox:
Once you have enabled annotation processing in IntelliJ you can run the application and tests directly within the IDE without the need of an external build tool such as Gradle or Maven.
Configuring Eclipse IDE
If you wish to use Eclipse IDE, it is recommended you import your Micronaut project into Eclipse using either Gradle BuildShip for Gradle or M2Eclipse for Maven.
Micronaut requires Eclipse IDE 4.9 or above |
Eclipse and Gradle
Once you have setup Eclipse 4.9 or above with Gradle BuildShip first run the gradle eclipse
task from the root of your project then import the project by selecting File → Import
then choosing Gradle → Existing Gradle Project
and navigating to the root directory of your project (where the build.gradle
is located).
Eclipse and Maven
For Eclipse 4.9 and above with Maven you need the following Eclipse plugins:
Once installed you need to import the project by selecting File → Import
then choosing Maven → Existing Maven Project
and navigating to the root directory of your project (where the pom.xml
is located).
You should then enable annotation processing by opening Eclipse → Preferences
and navigating to Maven → Annotation Processing
and selecting the option Automatically configure JDT APT
.
Configuring Visual Studio Code
Micronaut can be setup within Visual Studio Code. You will need to first install the The Java Extension Pack.
You can also optionally install STS to enable code completion for application.yml . |
If you are using Gradle prior to opening the project in VSC you should run the following command from a terminal window:
./gradlew eclipse
Once the extension pack is installed and if you have setup terminal integration just type code .
in any project directory and the project will be automatically setup.