Search

Dark theme | Light theme
Showing posts with label Maven:Reference. Show all posts
Showing posts with label Maven:Reference. Show all posts

May 25, 2009

Add CSS link in page header for Maven project site

Using Maven's site plugin is very powerful. It is so easy to generate a site with links to documentation and write our own documentation in APT or XDoc format. To keep a consistent look-and-feel it is a good idea to use a CSS file and define the look-and-feel of the site in this file. If we create the file src/site/resources/css/site.css Maven will automatically include it. In the generated pages we find a reference to the site.css:

<style type="text/css" media="all">
      @import url("./css/maven-base.css");
      @import url("./css/maven-theme.css");
      @import url("./css/site.css");
</style>

Notice the relative reference that is used. This means subprojects or submodules of our Mavenized application cannot reach this file. One way to deal with this is to write our own Maven site skin. We can create the look-and-feel in the site skin and use it among the several submodules.

But what if the company already provides a skin we must use? We cannot use more than one skin, so we need another way out. We add a reference to site.css in our HTML head section which can be recognized by all submodules. In the src/site/site.xml file we add the following:

<body>
  <head>
    <link rel="stylesheet" href="/css/site.css" type="text/css" />
  </head>
</body>

Now all generated pages will have the <link> tag in the HTML head section.

May 19, 2009

Development JAR signing in Maven

For development purposes we needed to use a signed JAR in our project. First we created a keystore:

$ keytool -genkey -alias applet -keyalg RSA -keystore src/main/keystore/signing-jar.keystore -storepass applet -keypass applet -dname "CN=domain"

We can than use the following Maven POM file definition:

...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>sign</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <keystore>src/main/keystore/signing-jar.keystore</keystore>
        <alias>applet</alias>
        <storepass>applet</storepass>
        <verify>true</verify>
    </configuration>
</plugin>
...

If we run mvn package we get a signed JAR file. Of course this is only useful for development purposes. To disable the JAR signing we invoke mvn package -Dmaven.jar.sign.skip=true

May 13, 2009

Configure Maven Jetty plugin for SSL communication

For a recent project I had to enable SSL communication for the Maven Jetty plugin. So when we run mvn jetty:run we must be able to use the https protocol. After browsing several mailing list I found the answer. For development we can create our own security certificate and configure the plugin to use it.

To create the development certificate we run the following command:

$ keytool -genkey -alias jetty6 -keyalg RSA -keystore target/jetty-ssl.keystore -storepass jetty6 -keypass jetty6 -dname "CN=your name or domain"

Fill in your name or domain for the -dname "CN=" option. We need the keystore and key password again when we configure the plugin in the Maven POM. The following code fragment shows how the Jetty plugin supports SSL:

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <configuration>
        <contextPath>/context</contextPath>
        <scanIntervalSeconds>5</scanIntervalSeconds>
        <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                <port>8080</port>
                <maxIdleTime>60000</maxIdleTime>
            </connector>
            <connector implementation="org.mortbay.jetty.security.SslSocketConnector">
                <port>8443</port>
                <maxIdleTime>60000</maxIdleTime>
                <keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
                <password>jetty6</password>
                <keyPassword>jetty6</keyPassword>
            </connector>
        </connectors>
    </configuration>
</plugin>

In the connectors element we have defined connectors for http listening on port 8080, and for https listening on port 8443. At line 14 we reference the keystore file we have created with keytool. Lines 15, 16 define the password value.

To test this configuration we can invoke mvn jetty:run and open a web browser with address https://localhost:8443/context. We must not forget to use https for the protocol.

We generated the keystore by using the keytool command from the Java Development Kit. But there is a Maven plugin that does the same thing, but we can define all arguments for keytool in our POM. When we run mvn keytool:genkey the keystore is generated and with mvn keytool:clean we can remove the keystore again. If we want to attach the creation of the keystore to the Maven generate-resources phase we must first make sure we invoke keytool:clean otherwise we get an error from keytool that the specified alias already exists. So we can add the following to our POM:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>keytool-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <id>clean</id>
            <goals>
                <goal>clean</goal>
            </goals>
        </execution>
        <execution>
            <phase>generate-resources</phase>
            <id>genkey</id>
            <goals>
                <goal>genkey</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
        <dname>cn=www.mrhaki.com</dname>
        <keypass>jetty6</keypass>
        <storepass>jetty6</storepass>
        <alias>jetty6</alias>
        <keyalg>RSA</keyalg>
    </configuration>
</plugin>

Now we can invoke mvn jetty:run and the keystore is automatically generated and used by the Jetty plugin.

May 1, 2009

Use anchors in Maven APT project site documentation

Maven supports the APT (Almost Plain Text) format to create documentation. We can even create anchors and links to the anchors in our documentation:

{Simple title}

    We can write our documentation paragraph as always with <<bold>>
    or <italic> text.

{Another section}

    We can link to our {{{Simple_title}Simple title}} section by using the anchor 
    link. We must make sure we replace spaces in an anchor text with underscores.

This will result in the following HTML:

<div class="section"><h2><a name="Simple_title">Simple title</a></h2> 
<p>We can write our documentation paragraph as always with <b>bold</b> or <i>italic</i> text.</p> 
</div> 
<div class="section"><h2><a name="Another_section">Another section</a></h2> 
<p>We can to our <a href="#Simple_title">Simple title</a> section by using the anchor link.</p> 
</div>

May 26, 2008

Maven support for NetBeans

Best practices for Apache Maven in NetBeans
Good article with all the information about NetBeans support for Maven. (Which is extensive by the way).

NetBeans platform development with Maven
Extending NetBeans or creating new applications using NetBeans platform can also be done with Maven as build application.

April 25, 2008

Links for Maven reference

Maven: The Definitive Guide
Online book with a lot of good stuff about Maven. Great to get some more detailed info and contains almost everything you need in one place.

Maven site
The original Maven site with links to plugins, documentation and the code.

Mojo project with plugins for Maven
Before developing our own plugin this is a good place to take a look. Most stuff is already developed by someone else and maybe we can find it here.