Maven settings.xml config for default Sonar db server

If you want to set a default Sonar configuration for all your Maven projects to run against, you can add your settings as a profile in the profiles section in your default settings.xml in either your ~/.m2 dir or your maven_install_dir/conf dir (depending which you’re using)

<profiles>
    <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- MySQL -->
                <sonar.jdbc.url>
                    jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8
                </sonar.jdbc.url>
                <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
                <sonar.jdbc.username>your_sonar_db_userid</sonar.jdbc.username>
                <sonar.jdbc.password>your_sonar_pwd</sonar.jdbc.password>
            </properties>
        </profile>
  </profiles>

 

Maven packaging notes

maven-dependency-plugin: Copy dependent jars into a /lib/ dir to be bundled with the package goal (note that you can’t have jars within jars and have them accessible on the classpath, so this just helps package the jars with your distribution):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>

            <configuration>
            <outputDirectory>target/classes/lib</outputDirectory>
            <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>

        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>sources</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <verbose>true</verbose>
        <detail>true</detail>
        <outputDirectory>.</outputDirectory>
    </configuration>
</plugin>

 

 

JSF 2.0 namespaces

Here’s the namespace declarations for the JSF 2.0 tags:

<!DOCTYPE HTML>
<h:html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">

For JSF 2.2 the URLs have changed. See post here.

Deploying a Maven-based web project from Eclipse

Here’s the problem: you start with a Web project in Eclipse, created via one of the Wizards. At some point you convert it to a Maven project, but when you deploy the project from Eclipse, your web content in /src/main/webapp is not deployed, because Eclipse is not aware of the Maven folder structure.

I’ve done this multiple times in the past and usually work out a way to build a ear/war and manually deploy it to my server or via a script instead, because I can’t work out how to get a converted project to deploy in Eclipse 🙂

The magic to get this to work is to add the maven-war-plugin to your Maven pom.xml file:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>