Versions Compared

Key

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

...

This command will create a Struts2 application prototype, in the 'app' directdory. From there you can use the files in directory 'app' as a starting point for your new Struts2 application project.

Configuring the Dependencies

Most of the time there is no configuration for repositories in the pom.xml configuration file
because there is a built-in default repository (pointing to http://repo1.maven.org/maven2Image Added).
Most of the time, open source projects will publish artifacts to the central repository, but they
can also host their own repositories and not made them available.

Hibernate, which is now under the JBoss umbrella of projects, is such an example.

To integrate Hibernate into the web application, two different types of dependencies are
required: for the Hibernate code itself, and for the JPA and transactional APIs that are implemented.
The JBoss repository contains both of these types, so configuring the pom.xml configuration
file is easy. A new repositories tag is added under the top-level project tag, which in
turn contains a repository tag with an id tag (providing a unique identifier) and a url tag
(that supplies the URL of the repository).
<project>
...
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.com/maven2Image Added</url>
</repository>
</repositories>
<project>

As well as the common repositories outside our organization, we have created repositories inside GLAST. This is a great strategy because developers know that if an artifact is installed in the GLAST repository, it can be used. Along with external artifacts, this
repository hosts internal projects and libraries to provide a central access point here at SLAC.

Installing new artifacts in the GLAST Maven 2 repository

When dealing with a build tool that automates dependency management (especially downloading the
libraries for you) such as Maven2, the artifact or library that you require may not be available.
The following are two scenarios when JAR files are not automatically retrieved and installed:
? The distributing organization does not publish the JAR files to the standard remote repositories (such
as ibiblio.com).
? A legal restriction such as a user acknowledgment or license agreement needs to be accepted before
using the files.
In either of these cases, additional steps are required before the JAR file can be configured in the
pom.xml configure file and utilized in your application:

1. Locate the download location for the libraries that are needed
2. Accept the license agreement (if applicable), and download the file.
3. If the files are downloaded as archives (other than JAR files), expand the archive into a working
directory.
4. Install the required libraries into your local Maven2 repository (usually in ~/.m2)

Once downloaded, Maven2 provides a command to install the library into the correct local repository
location and to create the necessary metadata files within the repository. The command has the following
form:

Code Block

mvn install:install-file -DgroupId=<groupId>
-DartifactId=<artifactId> 
-Dversion=<version>
-Dpackaging=jar 
-Dfile=</path/to/downloaded/file>

For an example, let's take the Hibernate annotations file (remember this is an example and this step
doesn't need to be performed). Following is the dependency configuration that will be added into the web
application's pom.xml configuration file:

Code Block

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.2.1.ga</version>
</dependency>

This provides all the information needed to issue the install command from earlier. By substituting the
groupId, artifactId, and version information, and issuing the command from the directory that the
hibernate-annotations.jar (the name of the file that was downloaded) is located, the Maven2 command
to install the library becomes the following:

Code Block

mvn install:install-file -DgroupId=org.hibernate
-DartifactId=hibernate-annotations
-Dversion=3.2.1.ga -Dpackaging=jar -Dfile=hibernate-annotations.jar

The preceding pom.xml configuration is now able to access the dependency from your local development
environment.

The next step is to configure Maven2 so that the application can access the Hibernate
dependencies. We saw above that this is achieved by adding the dependency file
information to the dependencies node of the pom.xml configure file. When configured in this
manner, Maven2 goes out and retrieves the JAR files from either a local repository or the
newly configured remote repository.

Code Block

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.1.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.2.1.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.2.1.ga</version>
</dependency>

Note Each Hibernate dependency also has its own dependencies, known as transitive dependencies.
When the project you are using is built for Maven2, the transitive dependencies are configured and downloaded
automatically with the dependency that you have configured. But occasionally, you will encounter
a project that has not been built for Maven2. In this case, you need to add each of the transitive dependencies
individually to the pom.xml configuration file manually.

Web application deployments on tomcat servers

...