Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Building IDE project files

Tips

...

Maven has a great feature that will allow you to build up your IDEA or Eclipse project files based on the project build structure. This is a great way to make sure all developers keep in sync and operate and maximum efficiency. The IDEA project files, in fact, are pre-configured in such a way that when built many of the common tasks ("execute all tests", "launch the showcase sample app", etc) are already defined in the Run/Debug menu.

IDEA

Before you build the IDEA project files, it might be helpful to understand that Maven can actually run a phase or a plugin. Up until now we've told Maven to run build phases (package, test, clean, install, etc). You can also specify a standalone plugin that isn't bound to any particular phase. In this case, we're invoking the "idea:idea" plugin (don't worry about the redundant text other than knowing it is required).

To get the most out of your IDEA environment, it is strongly recommended you use get the latest IDEA plugin for Maven. This is as simple as executing the following command from any directory:

Code Block

mvn -DconnectionUrl=scm:svn:http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-idea-plugin \
    -Dgoals=install \
    scm:bootstrap

Doing this will download and install the latest IDEA plugin for maven. This step will no longer be required as soon as the Maven team releases the next version of the plugin, which includes several major improvements used specifically by the Struts build.

Next, simple run the following command (the profiles are optional, but we encourage you to use them):

Code Block

> mvn -Pthirdparty,xwork idea:idea
Tip

If you find the xwork module causing you problems, such as displaying as "XWork" when it should be named "xwork", this is likely a bug in IDEA. To fix it, clear out your IDEA system cache and try again

This will generate project.ipr, project.iws, and an iml file for each module in the build. Open up project.ipr and you should be all set. If you ever need to rebuild your projects, running the command again will update your files without overriding any information that doesn't conflict. However, sometimes you may wish to overwrite the project files. To do so, you can do the following:

Code Block

> mvn -Doverwrite=true -Pthirdparty,xwork idea:idea

Eclipse

Eclipse is untested (most Struts users are IDEA users - sorry!), but you should be able to do:

Code Block

> mvn -Pthirdparty,xwork eclipse:eclipse

The Eclipse project files will not get any of the additional benefits, such as pre-built Run/Debug targets, that the IDEA project files use.

IMPORTANT: Running the sample webapps from Eclipse or non-IDEA IDEs

Currently the sample webapps can be deployed using QuickStart. With the switch to Maven, the expected location for the jars is no longer valid. Fortunately, QuickStart has a feature where it can read in one or more IDEA iml (module) file and use the jars specified there. So far the showcase webapp is configured to do this (see it's quickstart.xml file). This means that even if you're using Eclipse, it is recommended that you generate the IDEA project files so that you can run the Showcase webapp via QuickStart.

The settings, automatically baked in to the IDEA workspace file, needed to run Showcase under QuickStart are:

Code Block

Main class: org.apache.struts.action2.Main
VM params: none
Program params: quickstart
Working directory: webapps/showcase
Classpath: must include at least the struts module (Which contains the Main class)

Tips

A few helpful tips for using Maven are provided:

Offline mode

If you are disconnected from the internet or simply wish to make your build faster, just pass in the -o argument and maven won't check for new modules to download:

Code Block

mvn -o -Pthirdparty,xwork package

Skipping test execution

Although this shouldn't ever happen, sometimes tests do fail and you need to build Struts anyway. Getting around this is possible by adding the -Dmaven.test.skip=true parameter:

Code Block

mvn -Dmaven.test.skip=true -Pthirdparty,xwork package

Now the project will still build and tests just won't be executed. Please try to fix tests rather than skipping them!

Mirrors

The main mirror of central (also known as "ibiblio") is extremely slow and can be very unreliable. Fortunately, Maven supports mirrors. You can read more about them http://maven.apache.org/guides/mini/guide-mirror-settings.html, but the basic idea is that if you add the following to ~/.m2/settings.xml (or create the file if it doesn't exist), you can likely speed up the build process:

Code Block
xml
xml

<settings>

  <mirrors>
    <mirror>
      <id>dotsrc</id>
      <url>http://mirrors.dotsrc.org/maven2</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

</settings>
Note

Sometimes the mirrors have problems and/or aren't updated at the same frequency as the main mirror. If you have trouble building, try commenting out the mirror and see if that helps.

First time building

In some cases it has been seen that Maven will complain a module doesn't exist, even though it is part of the current build. This is especially likely when executing mvn package. A simple fix for this is to run mvn install instead. If you have to do this, it will probably only be a one-time thing.

...