From the alfresco wiki:
What is an AMP file?
An AMP file is a collection
of code, XML, images, CSS, etc. that collectively extend the functionality or
data provided by the standard Alfresco repository. For more information, see Developing an Alfresco Module.
An AMP file can contain as
little as a set of custom templates or a new category. It can contain a custom
model and associated UI customisations. It could contain a complete new set of
functionality, for example records management.
As a general rule of thumb,
anything that is considered to be an 'installable' extension to the Alfresco
repository should be called a module and packaged as an AMP file.
AMP files can be installed
into the Alfresco WAR using the Module Management Tool. An AMP file has a standard
format described below which can be customised if required.
AMP files can now also be
created via Apache Maven 2 archetypes and have their lifecycle and deployment
into Alfresco managed by the Maven Alfresco AMP archetype. For a full
description of Maven AMPs Alfresco support see Managing Alfresco Lifecyle
with Maven.
Once the contents of the AMP
file has been mapped into an Alfresco WAR using the Module Management Tool, the WAR can be deployed to the
application server. When the repository is next started, the installed module
configuration will be detected, and the repository will be bootstrapped to
include the new module functionality and data.
A couple of problems I have with AMP files with custom code and configuration:
- There is no easy way to back out an AMP
extension
(Can be a little annoying if you are developing multiple AMPs that might be
dependent on each other and files can be placed pretty much anywhere inside of the WAR File)
- AMPs are not easy to work with Dependency
Management.
(Major flaw in my eyes especially if you are trying to create base modules that
may share configuration/code with other modules)
A
couple of reasons I prefer to build my extensions with JAR files:
- You don’t need any tools to deploy them
(The Jar files can simply be placed in the server lib directory or you can use
tools like Maven to build the WAR file for you
and automatically place the dependent JARs into the WEB-INF lib
directory)
- It is simple to back out an extension, simply
remove the JAR file. You don’t need to roll
back to the original WAR and reapply any other AMPs
- The biggest reason I like to work with JAR files
is I can work on multiple modules and leverage dependency management.
As far as I can tell you can do everything you can with JAR
files in a much cleaner manner. You should still use AMP files but don't put custom code in them just pull in your dependent modules via Maven. The AMP will simply deploy your JARs into the WEB-INF/lib directory.
Here is a sample POM file you can use for an extension
project:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample.training</groupId>
<artifactId>alfrescoExtJar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Training Alfresco Extension</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://myNexus/nexus/content/repositories/releases/</url>
<uniqueVersion>false</uniqueVersion>
<layout>default</layout>
<name>My Nexus Repository</name>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>snapshots</id>
<name>My Nexus Snapshot Repository</name>
<layout>default</layout>
<url>http://myNexus/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>My Nexus Release</id>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<name>My Nexus</name>
<url>http://MyNexus/nexus/content/groups/public/</url>
</repository>
<repository>
<id>My Nexus Snapshot</id>
<releases>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<name>My Nexus Snapshots</name>
<url>http://MyNexus/nexus/content/groups/public-snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.alfresco.enterprise</groupId>
<artifactId>alfresco-core</artifactId>
<version>4.0.2.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.alfresco.enterprise</groupId>
<artifactId>alfresco-repository</artifactId>
<version>4.0.2.9</version>
<scope>provided</scope>
</dependency>
... Other Provided Dependencies are not listed because it made the post too long...
</dependencies>
<build>
<finalName>alfrescoExtJar</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>1.6</source>
<target>1.6</target>
<!-- set verbose to be true if you want
lots of uninteresting messages -->
<!-- <verbose>true</verbose>
-->
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>1.8.6-01</version>
<!--
<version>1.7.10-06</version> -->
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
This POM file is quite length because I have included all of
the Alfresco Provided dependencies. You
could clean this up by putting them in a separate POM file and adding that as a
dependency.
<dependency>
<groupId>com.sample.commons.alfresco</groupId>
<artifactId>alfresco-include</artifactId>
<version>4.0.2.9</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
If you had other reusable alfresco libraries you can include
them by just inserting another dependency…
<dependency>
<groupId>com.sample.training</groupId>
<artifactId>shared</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
This is great and all but how does this work in my IDE if I
want to run this. You can add a maven
webapp project to your IDE and use a POM similar to this one:
<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.sample.training</groupId>
<artifactId>alfresco</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Training Alfresco Webapp</name>
<url>http://maven.apache.org</url>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://myNexus/nexus/content/repositories/releases/</url>
<uniqueVersion>false</uniqueVersion>
<layout>default</layout>
<name>My Nexus Repository</name>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>snapshots</id>
<name>My Nexus Snapshot Repository</name>
<layout>default</layout>
<url>http://myNexus/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>My Nexus Release</id>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<name>My Nexus</name>
<url>http://MyNexus/nexus/content/groups/public/</url>
</repository>
<repository>
<id>My Nexus Snapshot</id>
<releases>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<name>My Nexus Snapshots</name>
<url>http://MyNexus/nexus/content/groups/public-snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.alfresco.enterprise</groupId>
<artifactId>alfresco</artifactId>
<version>4.0.2.9</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.sample.training</groupId>
<artifactId>alfrescoExtJar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>alfresco</finalName>
</build>
</project>
Include the alfresco WAR as a dependency and add you Ext
dependencies. This will build you a WAR
file with your JARs place in the lib directory. If you are using eclipse you can leverage WTP
and deploy to a tomcat server. You can
do the same technique with share.
This technique has helped to get teams up and running in
minutes. If you hook this up with a CI
system like Jenkins you will have a well-oiled machine building your artifacts
that can easily be deployed. You can now
deploy the Jar files and also deploy prebuilt WAR files. When you need to test you customizations out
against another version of Alfresco, simply change a version # in your POM
files and try it out.
When you are ready to deploy build an AMP with no custom code or configuration. Just pull in the dependencies. This will build and AMP file that basically only contains Jar files.