Blogs

SpringSource Blog

Maven PAR Plugin 1.0.0.M1

Ben Hale

Shortly after the introduction of SpringSource dm Server (Application Platform at the time), Thorsten Maus created a Maven plugin for creating PAR files. This was a great community contribution and we even used it in the Getting Started Guide for dm Server 1.0.x.

As dm Server's 2.0 milestones have progressed we've been adding new functionality to the PAR file. The most interesting feature is that now a PAR file can contain more than just JAR files. With the introduction of OSGi RFC 66, the dm Server has deprecated Web Modules in favor of the standard Web Container files using a .war extension.  Because of this, the PAR plugin needed to be updated to support these different types as dependencies.  Thorsten graciously agreed to donate his code to SpringSource and I'm pleased to announce the 1.0.0.M1 release of the Apache Licensed Maven PAR Plugin.

Usage

Use of the plugin has changed only slightly and can now default all of the information needed.

Repository

To get the plugin, you'll need to reference the SpringSource Enterprise Bundle Repository as a <pluginRepository/>

<pluginRepositories>
    <pluginRepository>
          <id>com.springsource.repository.bundles.milestone</id>
          <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Milestones</name>
          <url>http://repository.springsource.com/maven/bundles/milestone </url>
     </pluginRepository>
</pluginRepositories>

Build Plugin

Next you will need to set your packaging type to par and add the plugin to your build plugin list.

<build>
     <plugins>
          <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-par-plugin</artifactId>
               <version>1.0.0.M1</version>
          </plugin>
     </plugins>
</build>

By default all of the PAR manifest headers are populated using defaults from the POM but can be overridden with configuration.

Header POM Element
Application-SymbolicName ${project.artifactId}
Application-Name ${project.name}
Application-Description ${project.description}
Application-Version ${project.version}
<build>
     <plugins>
          <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-par-plugin</artifactId>
               <version>1.0.0.M1</version>
               <configuration>
                   <applicationSymbolicName>override.symbolic.name</applicationSymbolicName>
                   <applicationName>Override Name</applicationName>
                   <applicationDescription>Override Description</applicationDescription>
                   <applicationVersion>1000.0.0.override</applicationVersion>
               </configuration>
          </plugin>
     </plugins>
</build>

There is also a <fullyQualifiedNames/> configuration tag that selects between ${groupId}.${artifactId}-${version}.${type} and ${artifactId}.${type} for the file names of the files contained within the PAR file. This value defaults to false.

PAR

Next, add your list of dependencies. The plugin packages all of the direct dependencies listed in the POM. It does not care about scopes or transitive dependencies.

<dependencies>
    <dependency>
        <groupId>com.springsource.dmserver</groupId>
        <artifactId>greenpages.app-solution</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>com.springsource.dmserver</groupId>
        <artifactId>greenpages.jpa-solution</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>com.springsource.dmserver</groupId>
        <artifactId>greenpages.db-solution</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>com.springsource.dmserver</groupId>
        <artifactId>greenpages.web-solution</artifactId>
        <version>${project.version}</version>
        <type>war</type>
    </dependency>
</dependencies>

Build

Run mvn package.

[INFO] [par:par]
[INFO] Assembling Artifacts for PAR 'solution/greenpages/target/greenpages-solution-1.0.0.SNAPSHOT.par'
[INFO]   Added 'greenpages.app-solution.jar'
[INFO]   Added 'greenpages.jpa-solution.jar'
[INFO]   Added 'greenpages.db-solution.jar'
[INFO]   Added 'greenpages.web-solution.war'

The Future

Please clone the source code and give me feedback in the comments and suggestions at the dm Server JIRA.

Similar Posts

Share this Post
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • Technorati
  • Twitter
 

25 responses


  1. Can springsource enable HTTP View for all git reprositories. This will help it to reach wider audiences who are behind proxies and firewalls.


  2. @Anoop,

    I'll talk to our sysadmins and see what I can do.


  3. Hi There,

    I don't know if this is a bug, while using this plugin builds the par fine, maven complains during an install or deploy that there's no primary artifacts to install and silent skips over installing the par. We've had to revert to the older version of the plugin in order to get our par to build and deploy correctly.

    If this is a bug I'm happy to raise it, but not sure where to do it.

    Thanks,
    Adrian.


  4. @Adrian

    Yup, I caught that shortly after the M1 release and fixed it in source control. Are you able to build a snapshot to test yourself?


  5. Thanks Ben,

    I'll try to do a build later this week to test. But good to hear that a fix has gone in.

    Cheers,
    Adrian.


  6. @Adrian,

    Let me know if you have success and I'll do another release after you're done so you have an official to work with.


  7. The does not seem to work. Always makes the short names. Here is my configuration:

    org.apache.maven.plugins
    maven-par-plugin
    1.0.0.M1

    true
    com.db.ged.riskservices.pks-adapter
    2009.01
    PKS
    PKS

    Do I use it correctly?


  8. @Leonid

    It's hard to tell actually :) Can you repost your configuration with escaped tags?


  9. My previous post got broken because I used the xml in there.

    Anyway, my problem is that the fullyQualifiedName tag does not work as advertised. I set it to "true", and still I am getting the short bundle names in the par.

    It was working in version 0.2.0 with the "fqn" tag.

    What is the story?


  10. @Leonid

    The fqn tag was expanded out to <fullyQualifiedNames/> If you change that, does it work the way you'd expect?


  11. @Ben

    No, that's my point: fullyQualifiedNames tag does not work. Could you try it and let me know what you see?

    Thanks


  12. @Leonid

    I've just taken a copy of the GreenPages sample application (http://bit.ly/AWqkl) and modified the configuration to add <fullyQualifiedNames> The configuration looks like the following when complete:

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-par-plugin</artifactId>
    <version>1.0.0.RELEASE</version>
    <configuration>
    <fullyQualifiedNames>true</fullyQualifiedNames>
    <applicationSymbolicName>greenpages</applicationSymbolicName>
    </configuration>
    </plugin>

    This produces the following out when run

    [INFO] Assembling Artifacts for PAR '/Users/benhale/Downloads/greenpages-2.0.0.RELEASE/solution/greenpages/target/greenpages-solution-2.0.0.RELEASE.par'
    [INFO] Added 'com.springsource.dmserver.greenpages.app-solution-2.0.0.RELEASE.jar'
    [INFO] Added 'com.springsource.dmserver.greenpages.jpa-solution-2.0.0.RELEASE.jar'
    [INFO] Added 'com.springsource.dmserver.greenpages.db-solution-2.0.0.RELEASE.jar'
    [INFO] Added 'com.springsource.dmserver.greenpages.web-solution-2.0.0.RELEASE.war'

    The PAR produced contains files with the same names.


  13. Thanks Ben.

    The difference is, I use 1.0.0.M1 version as suggested above, and in your example it is 1.0.0.RELEASE.
    I wanted to try 1.0.0.RELEASE version, but maven could not download it. Apparently it is not in the "http://repository.springsource.com/maven/bundles/milestone" repository.
    So I tried to guess that it is in 'http://repository.springsource.com/maven/bundles/release". Is this the right place?
    It did download the plugin from there, but it still did not work for me.
    Then I noticed one more difference. In your example it only has two parameters: fullyQualifiedNames and applicationSymbolicName. I have a few more. So I commented out the extra stuff. But it complained that I don't have the required applicationDescription parameter.

    Bottom line is, I believe that the version you are using is different. How does it work for you without the applicationDescription ?


  14. Ben,

    I found what the problem is. There is a typo on this page. It says: "fullyQualifiedName", but should be "fullyQualifiedNames", as in your example.

    The RELEASE version also answered another question that I was about to ask. The M1 version required to call the "package" stage, and "install" did not work. Now the "install" properly does the packaging and installation. The "deploy" also works as expected.

    Thanks,

    Leonid


  15. @Leonid,

    Thanks for the tip about the typo. I've updated the post with the proper tag name.

    The release repository is the proper location for the 1.0.0.RELEASE version (and subsequent releases). A good place to keep an eye on changes and features being added is in the fisheye for the maven-par-plugin. https://fisheye.springsource.org/changelog/maven-par-plugin

    The way the sample works without applicationDescription is by the use of defaulting. Since the POM has a ${project.description} specified, it's automatically populated in the par-plugin configuration. One thing that you have illustrated though is that Application-Description is not a required header in a PAR. I'm going to fix and rev the release shortly making that and some of the other headers properly optional.

    Thanks again for looking at the plugin and providing feedback.


  16. Why are you using org.apache.maven.plugins as the group for this? Is this associated with the apache sandbox effort here?:

    http://svn.apache.org/repos/asf/maven/sandbox/trunk/plugins/maven-par-plugin/pom.xml


  17. @Zac,

    We used the org.apache.maven.plugins group because that is the only group that Maven will search automatically for a plugin based on convention. Any other group would have required extra user configuration. See here: http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html


  18. @Ben,

    Finally got to test this plug-in after doing a build with git and it worked well for me. I'll revert my builds back to the older version until the new milestone is published.

    Cheers,
    Adrian.


  19. @Adrian

    There is now a 1.0.0.RELEASE version available for you.


  20. @Ben – I see, but as it also says on that page, the Maven project is assumed to have control over that groupId. You are colliding with an existing unrelated plugin.

    http://maven.apache.org/guides/mini/guide-naming-conventions.html

    Since you are already asking users to add a repository, adding a pluginGroup is a reasonable step, and would avoid confusion.


  21. @Ben

    As someone using Maven in anger, you might like to comment on http://jira.codehaus.org/browse/MNG-4391, which is proposing a cleaner way (for Maven 3) to deal with artifactId changes that come from the use of Spring EBR bundles. It would be good to get a "SpringSource view" on this, as you guys are using Maven quite heavily now.


  22. I'm trying to use this plugin to build a par file, however I could not include within this par file the file META-INF/persistence.xml assuming that this folder META-INF is in src/main/resources of my maven project.

    Could you please if it is possible to do it?

    Thanks.


  23. PAR files are not supposed to have a persistence.xml file in META-INF/ in fact the only thing they can currently contain are JARs at the root level. Therefore the plugin does not support including any files other than JARs and putting them in the root level.


  24. Is this project dead? Can find very little reference to it anywhere – which is a shame, since I'm looking for something to generate par files for our company. I managed to download the existing plugin off springsource, but can't find any documentation for it. Is there a way to get it to include the transitive dependencies included on your local repo?


  25. Seth, there is a little, albeit old, documentation on the use of that plug in here: http://www.eclipse.org/virgo/documentation/virgo-documentation-2.1.1.RELEASE/docs/virgo-getting-started/html/ch07s04.html

One trackback

Leave a Reply