Views

Getting Started with IntelliJ IDEA

IntelliJ IDEA is a commercial alternative to the LDSTech IDE. IntelliJ can be used for developing applications use the LDS Java Stack. This tutorial assume that you already have IntelliJ installed and running.

Opening a Java Stack Application

When the Open Project dialog comes up, go the project's root directory, select the pom.xml file, and select OK. IntelliJ will then import your project and all of its modules.

As the project gets imported, IntelliJ may offer to add various .iml files to Subversion for you. Select No when these dialog boxes appear. All the needed project configuration is held in the pom.xml files

Configuring Maven in IntelliJ

IntelliJ can import Maven pom.xml files without any configuration changes. However, IntelliJ cannot execute Maven tasks without referring to a Maven installation. Older versions of the Stack may require Maven 2.

For building projects using Stack 2.1.x, download the latest version of Maven 2.0.x

For building projects using Stack 2.2+ and 3.x, download the latest version of Maven 3.0.x

Unzip the archive to a location on your hard drive

Set the environment variable M2_HOME to the folder where you installed Maven. By default, IntelliJ refers to M2_HOME to determine what Maven installation to use to run Maven goals.

(Recommended) Add %M2_HOME%\bin to your PATH environment variable.

You may work on projects that require different versions of Maven. To specify a version of Maven for a particular project, do the following:

Open the project, then go to File | Settings...

After the Settings dialog opens, select Maven in the Project Settings list

Under the Maven settings, go to Maven home directory and select the Override check box to the right of the input box. In the input box enter the location of the Maven installation you would like to use on the project.

If you have errors like unable to get dependency information unable to read the metadata file for artifact

open settings -> maven -> importing

check the box Use Maven3 to import project

Deploying and Running Applications

Creating a Configured Tomcat Instance

Java Stack applications have a deploy module that contains deployment properties for each environment the application will be deployed in (dev, test, staging, production, etc.). These properties hold values specific to each of these environments such as database connection information, logging settings, and Tomcat settings.

The LDSTech IDE uses these properties automatically when running Tomcat. When using IntelliJ, you must create a custom Tomcat instance that will use these properties. Fortunately, the Stack provides a relatively simple way of doing this.

Perform a Maven Install on the Project

NOTE: This must be done before creating the custom Tomcat instance so that the deployable war is available for configuring the Tomcat instance.

Select the Maven Projects button on the right side of the IDE window

Select the root module of the project

Expand the selection to Lifecycle | install

Click on the Run Maven Build button at the top of Maven Projects window

Rename the configuration to something more readable, like "Configure Tomcat"

Select the Runner tab, un-check the "Use Project Settings" box, then click the Add button next to the Properties list

Add a property called "tomcatTargetDir" that points to where you would like the Tomcat installation to be placed. By default, the Tomcat configuration plugin will place the custom Tomcat instance in PROJECT_ROOT/deploy/target. Since this directory will be deleted when executing a Maven clean goal, it is recommended that you specify a directory outside of your project to store the custom Tomcat instance.

Click OK to add the new Maven property

In the "Before Launch" section click the plus button (you may need to scroll or resize the window).

Choose "Run Maven Goal" at the bottom of the list.

Expand the root of your project (you can expand the deploy module instead of the root if you prefer).

There will be multiple artifacts listed. Select the artifact that ends in ...-web:war exploded.

In Application context field, enter the context path for your project. It is recommended that you specify the same context path that the Maven project has. In most cases, the context path can be found in the root POM file of your project as a contextRoot property.

Click OK to close the Select Artifacts to Deploy dialog (IntelliJ 11 and earlier)

Click OK

To run the Tomcat configuration, select the newly-created run configuration from the list of configurations on the main tool bar , then click the Run button . This will launch Tomcat and open a browser to your application.

JVM Settings for Tomcat Instance

While projects using the LDS Tech IDE leverage the jvmarg.properties file in a Stack project configure settings for the custom Tomcat instances, IntelliJ does not. To explicitly add the JVM arguments to your custom Tomcat instance, do the following:

Select Run | Edit Configurations from the drop down menu.

Select your Stack application run configuration from the list of configurations in the Run/Debug Configurations dialog. The configuration should be listed under the Tomcat Server section of configurations.

In the VM options entry box, enter the JVM arguments that you would like to apply to the configuration