We should create a resources directory to hold our application configuration and logging configuration files. The standard Maven directory for this is src/main/resources.
- Expand the project.
- Expand the src folder.
- Right-click the main folder.
- Select New > Folder and call it resources.
- Drag and drop the logback.xml file into the src/main/resources folder.
Maven allows us to specify properties that we can use in our POM. This provides us an easy mechanism of altering certain aspects of our project in bulk (I recognise that find/replace can do that too). Let's use project properties to control the versions of our packages. Change the properties section of the POM to match the following.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.apache.myfaces.core.version>2.2.7</org.apache.myfaces.core.version>
<org.eclipse.jetty.version>9.3.0.M1</org.eclipse.jetty.version>
<ch.qos.logback.version>>1.1.2</ch.qos.logback.version>
<org.slf4j.version>1.7.6</org.slf4j.version>
</properties>
We have created one property tag for each group of versions. This gives us a nice shortcut to update the versions of our packages in future. We access the property using the syntax ${property_name}. We will also change the type of our project from Java Archive (JAR) to Web Archive (WAR). This will make it asy for us to deploy it.
We will also give Maven some information about the Java environment we are going to be using. We will do this incase our developers are using Java 1.8 but we want to ensure the code will run under Java 1.7. To do this we add the following.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
We will also update the URL to point to our source forge project. With this in mind, our new POM becomes.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.sf.pbu.ontrack</groupId>
<artifactId>ontrack</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>ontrack</name>
<url>http://sourceforge.net/projects/pbuontrack/</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.apache.myfaces.core.version>2.2.7</org.apache.myfaces.core.version>
<org.eclipse.jetty.version>9.3.0.M1</org.eclipse.jetty.version>
<ch.qos.logback.version>1.1.2</ch.qos.logback.version>
<org.slf4j.version>1.7.6</org.slf4j.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${org.eclipse.jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${org.eclipse.jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${org.eclipse.jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp</artifactId>
<version>${org.eclipse.jetty.version}</version>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>${org.apache.myfaces.core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>${org.apache.myfaces.core.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
</dependencies>
</project>
Once this is done, Right-click your project in the Package Explorer pane and select Maven > Update Project and click OK. Our directory should look like the following.
I updated the post by changing the Maven Compiler Plugin Version to 2.5.1. This is the default version. I have updated the code on sourceforge.
ReplyDelete