Best Practices and Examples

Example Prototype File

As most of the prototype file will be generated this is sufficient for most cases:

i pkginfo
!include generated-prototype

If you have special entries/requirements that the plugin doesn't support add those to this file.

Example pkginfo

The pkginfo file will be interpolated when it is copied to the package. Interpolating the version is very useful so you don't have to update the file on each release.

PKG=...
NAME=...
DESC="${project.description}"
VERSION=${project.version}
ARCH=none
CLASSES=none
CATEGORY=application

Prototype Generation

Given this directory structure in target/solaris/assembled-pkg:

.
|-- etc
|   `-- opt
|       `-- myapp
|           `-- myapp.conf
|-- generated-prototype
|-- opt
|   `-- myapp
|       |-- META-INF
|       |   `-- MANIFEST.MF
|       |-- bin
|       |   `-- myapp
|       `-- etc
|           `-- myapp.conf
|-- pkginfo
`-- prototype

and this configuration in the POM:

<generatedPrototype>
  <directoryCollection>
    <mode>?</mode>
    <user>?</user>
    <group>?</group>
    <includes>
      <include>opt</include>
    </includes>
  </directoryCollection>
  <fileCollection>
    <mode>0755</mode>
    <includes>
      <include>opt/myapp/bin/*</include>
    </includes>
  </fileCollection>
  <fileEntry>
    <path>/etc/opt/myapp/myapp.conf</path>
    <mode>0700</mode>
    <user>root</user>
    <group>root</group>
  </fileEntry>
</generatedPrototype>

you will get this generated-prototype file:

d none /etc 0755 myapp myapp
d none /etc/opt 0755 myapp myapp
d none /etc/opt/myapp 0755 myapp myapp
f none /etc/opt/myapp/myapp.conf 0700 root root
d none /opt ? ? ?
d none /opt/myapp 0755 myapp myapp
d none /opt/myapp/META-INF 0755 myapp myapp
f none /opt/myapp/META-INF/MANIFEST.MF 0664 myapp myapp
d none /opt/myapp/bin 0755 myapp myapp
f none /opt/myapp/bin/myapp 0755 myapp myapp
d none /opt/myapp/etc 0755 myapp myapp
f none /opt/myapp/etc/myapp.conf 0664 myapp myapp

Note that the file /etc/opt/myapp/myapp.conf is included the default filter but was overridden with the <fileEntry> element.

Creating Solaris Packages of Other Artifacts

A common use-case for the plugin is to take a generic distribution in the form of either a tarball (tar.gz/tar.bz2) or a JAR file and turn that into a pkg file suitable for installation on a Solaris machine.

The following shows an example project structure and files that you need to use to do that.

Note that this use case is so common that the plugin might add support for doing this directly without the use of the assembly plugin in the future.

.
|-- pom.xml
`-- src
    `-- main
        |-- assembly
        |   `-- pkg.xml
        |-- resources
        |   `-- etc
        |       `-- opt
        |           `-- myapp
        |               `-- myapp.conf
        `-- resources-solaris
            |-- pkginfo
            `-- prototype

The POM includes the following dependency section which make sure the assembly plugin can use it. It is also important to get the build order correct if you are creating the bundle and the package in the same build.

<dependency>
  <groupId>${groupId}</groupId>
  <artifactId>myapp</artifactId>
  <version>1.1</version>
</dependency>

Configure the assembly plugin like this:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-2</version>
  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>directory-inline</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <finalName>solaris/assembled</finalName>
    <ignoreDirFormatExtensions>true</ignoreDirFormatExtensions>
    <descriptors>
      <descriptor>src/main/assembly/pkg.xml</descriptor>
    </descriptors>
  </configuration>
</plugin>

Note that at least version 2.2-beta-2 of the assembly plugin is required!

The pkg.xml must include at least the artifact we've listed, but can include any number of artifacts. The assembly id and format is significant. Also make sure you use a correct outputDirectory.

<assembly>
  <id>pkg</id>
  <formats>
    <format>directory</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <useProjectArtifact>false</useProjectArtifact>
      <includes>
        <include>org.codehaus.mojo.solaris:myapp</include>
      </includes>
      <unpack>true</unpack>
      <outputDirectory>/opt/myapp</outputDirectory>
    </dependencySet>
  </dependencySets>
</assembly>

The last step is to configure the prototype file generation, see Prototype Generation for an example.

After everything is set up a simple mvn install should download the artifact, generate the prototype, interpolate the pkginfo file and unpack the jar file.