cancel
Showing results for 
Search instead for 
Did you mean: 

how to make a custom action?

seraphon
Champ in-the-making
Champ in-the-making
Hi

I know there are Wiki pages whose very subject is the same than my topic
http://wiki.alfresco.com/wiki/Custom_Action_UI#Introduction
http://wiki.alfresco.com/wiki/Custom_Actions
http://wiki.alfresco.com/wiki/Packaging_And_Deploying_Extensions
I read those and I must say I still cant do it…

I tried first to follow CustomActionUi which looks great but I block at a fundemental level. Where do I put the java code??
From what I understood all the java classes are in some sort of library in the form of .jar but with all the wiki's and different method I m starting to mixing everything together and frankly I'm lost.

I first tried to do the custom action inside the alfresko SDK but if I build as a .jar I cant get it to work even though I do exactly what is said in the Deploying extensions. If I build so it goes directly inside alfresco.war well I* dont get a new alfresco.war but a .jar with alfresco.war inside???
So I abandoned it.

So sorry for the newb question, but can someone please tell me how to put an java file in a .jar and how to inject this .jar in wherever it must be injected?

If I put this topic in the wrong thread fell free to relocate it and sorry for the bother

Regards
Seraphon
9 REPLIES 9

rivetlogic
Champ on-the-rise
Champ on-the-rise
Hi Seraphon;

The Alfresco SDK has examples of how to package your extensions into a jar and inject that jar into the alfresco.war file.

Basically your project hierarchy should look something like this:

+ Project
    + source
        + alfresco
            + extension
                - *-context.xml
                - …
        + java packages
            - …
    - build.xml

and your build.xml should look something like this (that's how I do it anyway)

<?xml version="1.0"?>

<project name="Custom Action Build File" default="deploy" basedir=".">

   <property environment="env"/>
   <property name="tomcat.dir" value="${env.TOMCAT_HOME}/webapps"/>
   <property name="project.dir" value="."/>
   <property name="build.dir" value="${project.dir}/build"/>
   <property name="web.dir" value="${project.dir}/web" />
   <property name="package.file" value="${build.dir}/custom_action.jar"/>
   
   <target name="package-jar">
      <delete file="${package.file}" />
      <jar destfile="${package.file}">
         <fileset dir="${build.dir}"/>
      </jar>
   </target>
   
   <target name="integrate-extension" depends="package-jar">
         <available file="alfresco.war" type="file" property="alfresco.war.present" />
         <fail unless="alfresco.war.present"
               message="Could not find alfresco.war, please copy it to ${basedir}" />
         <zip destfile="alfresco.war" update="true">
            <zipfileset file="${package.file}" prefix="WEB-INF/lib" />
            <zipfileset dir="${web.dir}" />
         </zip>
   </target>
   
    <target name="remove-copy-war">
         <delete file="${project.dir}/alfresco.war"/>
       <copy file="${project.dir}/../alfresco.war" todir="${project.dir}"/>
    </target>
      
    <target name="undeploy" depends="remove-copy-war">
       <delete dir="${tomcat.dir}/alfresco"/>
         <delete file="${tomcat.dir}/alfresco.war"/>
    </target>
      
    <target name="deploy" depends="undeploy, integrate-extension">
         <copy file="${project.dir}/alfresco.war" todir="${tomcat.dir}"/>
    </target>
   
</project>

I made it simple by using the TOMCAT_HOME env variable, but you can get tomcat.dir from a properties file.

This also assumes that you will have a vanilla alfresco.war file in the folder one level above the Project folder.

The "deploy" ant target will copy the vanilla war into your project folder, build a jar containing the extensions, inject the jar into the alfresco.war file and deploy it to tomcat.

Note that the build.xml here does not compile the source. This scheme relies on Eclipse to do the compilation and building into class files. You can always modify the build script to run the compiler.

If you're using version 2.0 or higher you can also use an AMP file to package your extensions.

Hope this helps,

–Aladdin

seraphon
Champ in-the-making
Champ in-the-making
Thanks for the reply but it looks like I'm really not made for development..
I'm not sure I understood what you wrote.
So here is what I ve done after reading your post
Basically your project hierarchy should look something like this:

Code:
+ Project
    + source
        + alfresco
            + extension
                - *-context.xml
                - …
        + java packages
            - …
    - build.xml
Are you talking about the folder within the folder where I unzipped Alfresco SDK V2.0? such as
C:\Alfresco SDK\samples\CustomAction\source\alfresco\extension


If so I put my alfresco.war in samples, I ve replaced the code inside the build.xml by the one you gave me and then from eclpise I launched the run as->build ant option.
I got the following errors in the console Buildfile: C:\Alfresco SDK\samples\CustomAction\build.xml
remove-copy-war:
   [delete] Deleting: C:\Alfresco SDK\samples\CustomAction\alfresco.war
     [copy] Copying 1 file to C:\Alfresco SDK\samples\CustomAction
undeploy:
package-jar:
      [jar] Building jar: C:\Alfresco SDK\samples\CustomAction\build\custom_action.jar
integrate-extension:

BUILD FAILED
C:\Alfresco SDK\samples\CustomAction\build.xml:23: C:\Alfresco SDK\samples\CustomAction\web not found.

Total time: 2 seconds

What have I done wrong?
Regards Seraphon

rivetlogic
Champ on-the-rise
Champ on-the-rise
Hi,

You're getting this error because the build script can't find the "web" folder. In your case you probably don't need this folder so just remove the two following lines from your build.xml

<property name="web.dir" value="${project.dir}/web" />

<zipfileset dir="${web.dir}" />
Hope this helps,

–Aladdin

seraphon
Champ in-the-making
Champ in-the-making
ok the build worked and I got a new shiny alfresco.war that I ve put in the
tomcat/webapps folder then I restarted my server…..
Nothing works and worse of, it deleted everything that was in webapps before, which basically concisit on every important script and xml. I have to reinstall everything now, sniff

Ok now I abandon the very idea of using Alfresco SDK that has no serious documentation on it nor serious help and I will never ever touch to the alfresco.war file again

Regards
Seraphon whos starting to look green….

rivetlogic
Champ on-the-rise
Champ on-the-rise
Hi Seraphon,

Sorry about the deletion thing. The build script is set to undeploy everything in webapps before deploying a new version to make sure things are done cleanly.

Your config extensions should go in the project folder under the extensions folder or under your web container's shared classpath (eg. in tomcat that would be "tomcat_home/shared/classes/alfresco/extension").

It is generally good practice to keep your extensions externalized.

Best Regards,

–Aladdin

seraphon
Champ in-the-making
Champ in-the-making
Hi

thanks for the replies rivetlogic and dont worrie, I didnt do anything major so the deletion at this stage is not bad.

I m just curious but, even though I know you are right when you say its better to externalise our extensions, there are some times I dont know how to do it.

For example when you want to create/modify a role/permission the only way I know is to modify the files PermissionDefinitions.xml and web-client-config-action.xml.

How can you make custom.xml files in the extension folders that will somehow link to their counterpart in the webapp…. folder?


Regards
Seraphon who thinks customisation isnt for him

rivetlogic
Champ on-the-rise
Champ on-the-rise
Simple,

Given the way SDK projects are structured, your extension project can simply have the following:

+ Project
  + config
    + alfresco
      + model
        - permissionDefinitions.xml
Then, your build.xml can have a additional lines like so:


<property name="config.dir" value="${project.dir}/config" />

<target name="integrate-extension">
  …
  <zip destfile="alfresco.war" update="true">
    <zipfileset file="${package.file}" prefix="WEB-INF/lib" />
    <zipfileset dir="${config.dir}" prefix="WEB-INF/classes" />
  </zip>
  …
This will inject everything under the config dir into the vanilla alfresco.war. So you're really overwriting the file in the WAR directly but your changes are still considered external, so even if someone corrupts the deployed web app or deletes it you're still safe.

Hope this helps,

–Aladdin

seraphon
Champ in-the-making
Champ in-the-making
What do you mean by vanilla alfresco.war? It's not the same one than in the Webapps folder?

And as to how to use SDK
That how I understand what I must do :
I just have to launch eclipse than make a new project
after that I do the tree + Project
  + config
    + alfresco
      + model
        - permissionDefinitions.xml
By making each time a new folder (new->folder in eclipse)

After that I copy PermissionDefinitions than add whatever I want to add.
Finally I make a build like the first one you gave me plus the few lines from the precedent post.
Before building I put an Alfresco.war in the project folder.
After the building is done I overwrite the ancient Alfresco.war in the webapps folder by the new one.
Am I wrong?

Something I dont understand is that by doing this we still lose all the changes/customisation we can make when we change versions because we have to put the new Alfresco.war whos going to overwrite the ancient with all the changes..

sorry to abuse your good will but I just understood the simple fact I may understand all wrong.

Regards
Seraphon

rivetlogic
Champ on-the-rise
Champ on-the-rise
Hi,

Sorry for the late reply but basically you're 99% right. By vanilla alfresco.war I mean the one that you can download from the Alfresco website or build from the Alfresco src.

That file needs to go one level above the project folder. So if you're project is called Project and it lives in a folder called workspace then the vanilla alfresco.war goes in the workspace folder like so:

+ workspace
  + Project
  - alfresco.war
When the build starts this war file is copied into the Project folder, your customizations are injected in it and the new alfresco.war (with customizations) is copied to webapps.

So basically when you want to upgrade Alfresco versions you simply overwrite the vanilla alfresco.war that is in the workspace folder with the new one that you just downloaded and rebuild. Your customizations will then be injected into the new version of alfresco.war and deployed to webapps.

Hope this helps,

-Aladdin