Blog Archives

Java Development with NetBeans and Maven: Part 5

Overview

I hope we are well prepared for moving further to the very powerful “Maven” features, which we have known before, the “site”, especially the “report” integration to the outer world. There are many powerful “Maven Plug-in” provided by the “Maven” itself. You can see further information here. From now on, I will introduce you the “Reporting Plug-ins”.

The Report Plug-ins

Regarding the “Maven Plug-inhere, you may be noticed that there are two plug in which we used before. Guess what? The “project-info-reports”, the “mvn site” command itself and the “surefire-report”, the testing report for our previous JUnit. You already know how easy it is. The rest plug in also be same for sure. One picture can give us a thousand words. Here is my tested template “Project POM File” (pom.xml). Please feel free to modify it so that it is fit for your environment.


<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.scc.maven.java</groupId>
    <artifactId>MavenJavaPrj01</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>MavenJavaPrj01</name>
    <url>The Project web site URL</url>
    <description>The SDLC Learning</description>

    <licenses>
        <license>
            <name>Apache 2</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>

    <organization>
        <name>The Organization Name</name>
        <url>The Organization web site URL</url>
    </organization>

    <developers>
        <developer>
            <id>The developer id</id>
            <name>The developer name</name>
            <email>The developer email</email>
            <url>The developer web site URL</url>
            <organization>The developer organization</organization>
            <organizationUrl>The organization web site url</organizationUrl>
            <roles>
                <role>Role #1</role>
                <role>Role #2</role>
            </roles>
            <timezone>+7</timezone>
            <properties>
                <picUrl>The developer picture URL</picUrl>
            </properties>
        </developer>
    </developers>

    <issueManagement>
        <system>The issue management system, e.g. Bugzilla, TestTrack, ClearQuest, etc</system>
        <url>The issue management system web site URL</url>
    </issueManagement>

    <ciManagement>
        <system>The CI management system, e.g. Hudson,continuum, etc</system>
        <url>The CI web site URL</url>
        <notifiers>
            <notifier>
                <type>mail</type>
                <sendOnError>true</sendOnError>
                <sendOnFailure>true</sendOnFailure>
                <sendOnSuccess>false</sendOnSuccess>
                <sendOnWarning>false</sendOnWarning>
                <configuration>
                    <address>The sender email address</address>
                </configuration>
            </notifier>
        </notifiers>
    </ciManagement>

    <scm>
        <connection>scm:svn:Path/To/Repository</connection>
        <developerConnection>scm:svn:Path/To/Repository</developerConnection>
        <tag>HEAD</tag>
        <url>The SCM web site URL</url>
    </scm>

    <prerequisites>
        <maven>2.2.1</maven>
    </prerequisites>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <includes>
                        <include>
                            **/*TestSuite*.java
                        </include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <locales>en</locales>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>${basedir}/src/main/java</directory>
                <includes>
                    <include>log4j.dtd</include>
                    <include>log4j.xml</include>
                </includes>
            </resource>
        </resources>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>2.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.6</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-changelog-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <username>${svnUser}</username>
                    <password>${svnPassword}</password>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <configLocation>config/sun_checks.xml</configLocation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <stylesheetfile>${basedir}/src/main/javadoc/stylesheet.css</stylesheetfile>
                    <show>private</show>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <linkXref>true</linkXref>
                    <sourceEncoding>utf-8</sourceEncoding>
                    <minimumTokens>100</minimumTokens>
                    <targetJdk>1.5</targetJdk>
                    <excludes>
                        <exclude>**/*Bean.java</exclude>
                        <exclude>**/generated/*.java</exclude>
                    </excludes>
                    <excludeRoots>
                        <excludeRoot>target/generated-sources/stubs</excludeRoot>
                    </excludeRoots>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>2.5</version>
            </plugin>

        </plugins>
    </reporting>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

How the report is created.

It is simple by using the “mvn site” command, please refer to my previous post.

Are there any outer world plug in?

Yes, sure. Why not? Maven also mentioned in their plug in page as well. Please travel to the lower part of that page you will see the outer world for sure. I hope we are enjoy traveling.

Summary

We have finished preparing our development environment so that we can ensure that there should not be any surprise during the integration with the very powerful “Maven” features, the “site”, especially the “report”. As I’ve mentioned, This is a final article for my first series.

The well preparing will help us to reduce the defect, on the other hand, if the defect is less, the working time is less, too. That mean we will have more time to do other things in my life. For me is writing this blog. Next I will move further to the detailed “Java/JavaEE” development with “Maven” and will do my best to post for sure. Please stay tuned as always.

Java Development with NetBeans and Maven: Part 4

Overview

We have configured our environment so that we can declare our own information outside the “Project POM File” (pom.xml) such as the “Subversion” user id and password, the “Issue Tracker” user id and password. But it is only the “Maven” universe. We live in the bigger one, the integration universe. That means we need to know the other integrated system universe. Even we configure our credential / personal information with purpose to let “Maven” to use them when it connect to each sever. It is just our credential / personal information. Since “Maven” acts as a client, it should provide credential / personal information itself, too. Normally these communication is done via the “SSL”, especially via the “HTTPS”. There are some good practice to which I would like share.

The HTTPS Good Practice For The Client

Most of integration universe has been configured and deployed under the “Apache HTTP” umbrella. As I’ve mentioned before, the “HTTPS” is preferred. This means the “Maven” will connect to them via the “HTTPS”, too. The “Maven” acts as a client, they act as a server for sure. What is the issues? Well, It is a very well known issue.

The Certificate Management For The Client

Normally the server provides its “certificate” to the client for initiating the “SSL” connection. The client will determine if this “certificate” can be trusted. If yes, the conversation will be initiated.

If not the connection will be dropped. We may face a trouble like we cannot connect to server system shows me something about “no trusted certificate found” or other close to this.

The HTTPS Client Configuration Good Practice

I am informing you about the good practice for the client side who would like to connect to the server via “HTTPS”. If the client is a “Java” environment, the “Server Certificate” should be injected to the “truststore”.

The “Server Certificate” is not only limited to the server certificate itself, but also the “Signer Certificate”, too. Please note the “Signer Certificate” is a certificate of the trusted authority who sign the “Server Certificate”. The signer also not be limited at one level, it can be more. It is called “Certificate Chain”. During the checking & verifying If any of “Certificate” inside this “Certificate Chain” is trusted, It will be determined as trusted. This means if we have 3 levels “Certificate Chain”.

The checking step is as following: –

  1. If the level 3rd is trusted, it is determined as trusted. The checking stop here.
  2. If the level 2nd is trusted, it is determined as trusted. The checking stop here.
  3. If the level 1st is trusted, it is determined as trusted. If not the system may show us as “no trusted certificate found”.

For me, I have 2 levels which are created by the “openssl”. Anyhow it can be a 1 level as a self-signed as well.

By default the “truststore” is as following:-

Table 1: The default truststore for JRE

Default Trustsore for JRE

 

<JRE_HOME>/lib/security/cacerts

 

Example: C:/Java.Application/Sun/Java/jre1.6.0_21/lib/security/cacerts

Table 2: The default truststore for JDK

Default Trustsore for JDK

 

<JDK_HOME>/jre/lib/security/cacerts

 

Example: C:/Java.Application/Sun/Java/jdk1.6.0_21/jre/lib/security/cacerts

The injecting certificate command is as following: –

Table 3: The injecting certificate command

The injecting certificate command

 

keytool -importcert -trustcacerts -alias <MY_ALIAS> -file <Certificate> -keystore <Truststore>

 

Example: keytool -importcert -trustcacerts -alias myserver -file server.cer -keystore cacerts

Please note: you may be prompted to enter the password, the default password is changeit”.

Some of them are not default.

Some of them may have their own configuration environment instead, especially the “Subversion Client”. There are 2 types as global for whole client and per-user.

The server-wide

Unix:

/etc/subversion/servers

/etc/subversion/config

/etc/subversion/hairstyles

Windows:

%ALLUSERSPROFILE%\Application Data\Subversion\servers

%ALLUSERSPROFILE%\Application Data\Subversion\config

%ALLUSERSPROFILE%\Application Data\Subversion\hairstyles

REGISTRY:HKLM\Software\Tigris.org\Subversion\Servers

REGISTRY:HKLM\Software\Tigris.org\Subversion\Config

REGISTRY:HKLM\Software\Tigris.org\Subversion\Hairstyles

The per-user

Unix:

~/.subversion/servers

~/.subversion/config

~/.subversion/hairstyles

Windows:

%APPDATA%\Subversion\servers

%APPDATA%\Subversion\config

%APPDATA%\Subversion\hairstyles

REGISTRY:HKCU\Software\Tigris.org\Subversion\Servers

REGISTRY:HKCU\Software\Tigris.org\Subversion\Config

REGISTRY:HKCU\Software\Tigris.org\Subversion\Hairstyles

I prefer to use the per-user instead. Please note, I’m a “Windows Vista”, my configuration home for “Subversion Client” is “C:\Users\Charlee.Ch\AppData\Roaming\Subversion”. Normally the per-user configuration is created automatically by the “Subversion Client”. If the “Subversion Client” does not trust the “Server Certificate”, you may face the message like this, “Server certificate verification failed: issuer is not trusted”. It can be configured easily by using the “Subversion Client” command via a command line, for me it is a dos prompt, as the following:

Table 4: Configure subversion client to trust the server certificate

Configure subversion client to trust the server certificate

 

svn list https://<YOUR_DOMAIN/svn/path/to/repository

 

Example: svn list https://www.mydomain.com/svn/myproject/trunk

During executing this command, you will be prompted about the “Server Certificate”. Please press “p”, for accepting this certificate permanently. Anyhow the system may prompt you to provide the credential, please enter it properly. The top most certificate for the “Server Certificate Chain” will be stored at your local as the following: –

Table 5: The stored server certificate folder

The stored server certificate folder

 

<SVN_CLIENT_HOME>/auth/svn.ssl.server

 

Example: C:\Users\Charlee.Ch\AppData\Roaming\Subversion\auth\svn.ssl.server

Summary

At the moment, we understand that not only our credential / personal information should be configured, but also the “Maven” credential / personal information for itself should be configured, too. This will help us to achieve further integrating more simple and avoid the well know issues, such as the “HTTPS Client Configuration”. We are well prepared and ready for the next step, “Maven” integration with “Subversion” and “Issue Tracker”. I will post it soon, please stay tuned as always.