How to create and test a simple Java project with Maven and Intellij.
Step 1
Use maven to create the project skeleton.
Either
mvn archetype:generate
and pick Option 15 – maven-archetype-quickstart
Or
mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create \
-DgroupId=net.olioinfo \
-DartifactId=java_simple \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeGroupId=org.apache.maven.archetypes
Step 2
- Import into Intellij as a Maven project.
- Make sure that the SDK is set to a JAVA SDK
- On the Run menu, edit the Configurations to add a Junit test suite
- Select ‘Test all in package’
- Specify package
- Pick the top-level project directory as the working directory
- Ensure that ‘Make’ and ‘Build artifacts’ are checked
- Save
- The top two entries on the Run menu are now available
- The top ‘Run’ menu entry will run the last configuration applied
- The top ‘Debug’ menu entry will debug the last configuration applied
- Maven introduces two more entries below the top two entries on the Run menu
- ‘Run’ will run the configured maven goal (from the last configuration applied).
- ‘Debug’ should run maven in debug mode. Doesn’t seem to work
- All the standard maven targets work from command line. They will also function when included in an Intellij run-time configuration.
To build a Java webapp in Intellij Idea 9. follow the standard procedure documented in various places (to be supplied).
When the sample classes are examined, there will be undefined dependencies or imports for all the servlet – and any other J2EE – dependencies.
This is a change from Intellij 8, which included the J2EE libraries as compile-time options. To correct this there are two choices:
- Java 5 – Use the attached java 5 – J2EE jar and add as a compile-time dependency (taken from Intellij 8 )
- Java 6 – Use the attached java6 EE jars and add as a compile-time dependency (taken from glassfish v3 dependencies)
To import a Maven Groovy project into Intellij Idea 9:
- File > New Project
- Select ‘Import project from external model’. Click [Next]
- Select ‘Maven’. Click [Next]
- In the root directory window, navigate to the top-level directory of the Maven-Groovy project. Click [Next]
- Accept default offered for ‘Select Maven projects to import’. Click [Next]
- Accept default offered for project name. Click [Finish]
- All done!
Double-click on the video player to open on YouTube.
To set up an existing Ruby on Rails project in Intellij Idea 8:
- Install the Intellij Ruby plugin
- Preferences > Plugins > Available > Ruby
- File > New Project
- Select ‘Create Java Project from existing sources’ [Next]
- Navigate to the directory containing the source code [Next]
- Select ‘Create source directory’. Use the default. (This is one of the vital steps) [Next]
- Accept anything on the next screen relating to libraries [Next]
- Accept anything on the next screen relating to modules [Next]
- Accept the facets (this doesn’t appear to have any immediate impact) [Finish]
- File > Project Structure > [Platform Settings] > JDKs
- In the second panel, click the ‘+’ button to add a new SDK. Select ‘Ruby SDK’
- Navigate to the Ruby binary you want to use (usually /usr/bin/ruby or /usr/local/bin/ruby)
- Change the entry name if you want to
- [Apply], [OK]
- File > Project > [Project Settings] > Project
- Set Project SDK to the Ruby SDK you just created
- [Apply], [OK]
- Run > Edit Configurations
- Click the ‘+’ button to add a new configuration. Select ‘Rails’
- Name your configuration – e.g. ‘mongrel’
- Select a server – ‘mongrel’
- Select ‘Choose SDK from module’. Pick the module you’re in the process of configuring
- [Apply]
You should now be able to debug and run your project using Intellij.
These notes apply to Intellij Idea 8. They may apply to other versions.
To add a jar file to a project
- Highlight project in project tree
- Right-click (Ctrl-Click) and select ‘Module Settings’
- Libraries > Add
- Select an existing library or create a new one
- Select the library in the middle pane
- In right-hand pane, ‘Attach Classes’ and navigate to the jar file
- Select and apply
