Sunday, July 5, 2015

Debugging Alfresco and Share in Eclipse


Prerequisites:


  • Download Eclipse (Note: Eclipse should be JavaEE compitable and should have m2e installed)
  • Get the Alfresco maven archetype (follow the previous post)
  • Import the alfresco project in eclipse

Let's get started..

It is possible to start alfresco in debug mode by using the Maven mvnDebug command. 

Follow the below given steps to debug Alfresco and Share application in Eclipse

1- Right click the pom file of the project which you want to debug.

2- Select Run > Debug Configuration from main menu.

     





3- Click the New Launch Configuration icon on the top left of the dialog.

     




4- Give the Debug Configuration a suitable name.

5- For Goals enter integration-test (for SDK 2.x). For SDK 3.x on wards use goal as "alfresco:run"

6- For Profile enter amp-to-war (for SDK 2.x). For SDK 3.x on wards profile is not needed



    For SDK 3.x: 



7- In the Main tab ensure that Debug Output is selected.

8- Click Apply

9- On the JRE tab add the following VM arguments: -Xms1024m -Xmx4096m -XX:PermSize=1024m to avoid PermGenexceptions.

10- Click Apply.

11- Click Debug to run the Debug Configuration.

12- In Eclipse, click the Debug perspective and wait for the server to start.

By default Alfresco starts on 8080 port. You can change the port by modifying the value in pom.xml. or by adding/overriding the below property in pom.xml (you can find these properties in main project level pom.xml) 
Click Add  (in pom overview section in eclipse)  to add a new parameter name and value. You will enter a parameter name of maven.tomcat.port with a value of 8080.

For alfresco:
 <!-- (Alfresco SDK) | SDK properties have sensible defaults in the SDK parent, | but you can override the properties below to use another version. | 
    For more available properties see the alfresco-sdk-parent POM. -->
  <properties>
    <app.log.root.level>WARN</app.log.root.level>
    <alfresco.data.location>alf_data_dev</alfresco.data.location>
    <!-- This controls which properties will be picked in src/test/properties for embedded run -->
    <env>local</env>
    <!-- Defines the target WAR artifactId to run this amp, only used with the -Pamp-to-war profile | Defaults to a vanilla repository AMP, but could point 
      to your foundation / aggregator WAR . | Allowed values for Community: alfresco | share | Allowed values for Enterprise: alfresco-enterprise | share-enterprise 
      <alfresco.client.war>${alfresco.repo.artifactId}</alfresco.client.war> -->
    <!-- Context path to run alfresco on -->
    <alfresco.client.contextPath>/alfresco</alfresco.client.contextPath>
    <!-- Defines the target WAR groupId to run this amp, only used with the -Pamp-to-war switch . | Could be org.alfresco or your corporate groupId -->
    <!-- <alfresco.client.war.groupId>${alfresco.groupId}</alfresco.client.war.groupId> -->

    <!-- Defines the target WAR version to run this amp, only used with the -Pamp-to-war switch -->
    <!-- <alfresco.client.war.version>${alfresco.version}</alfresco.client.war.version> -->

    <maven.tomcat.port>8080</maven.tomcat.port>
  </properties>



13- For 'Share' we will follow exactly same process as we did above. Follow all steps from 1 to 10.

14- We have configured VM arguments at step 9. It is not required in case of share.

15- Share will run by default on 8081 port. you can modify the port number using the same approach as we did in 12th step. Click Add (in pom overview section in eclipse) to add a new parameter name and value. You will enter a parameter name of maven.tomcat.port with a value of 8081. This causes Share to listen on the 8081 port.

<properties>
        <!-- Defines the target WAR artifactId to run this amp, only used with the -Pamp-to-war switch
        | Allowed values: alfresco | share. In this case it's configured to use OOTB share -->
        <alfresco.client.war>share</alfresco.client.war>

        <!-- Since Alfresco is already running on port 8080, we run Share on port 8081 -->
        <maven.tomcat.port>8081</maven.tomcat.port>

        <!-- Used in share-config-custom.xml. By default points to standard location of Alfresco -->
        <alfresco.repo.url>http://localhost:8080/alfresco</alfresco.repo.url>

        <!-- Defines the log level used in log4j.properties -->
        <app.log.root.level>WARN</app.log.root.level>

    <alfresco.client.contextPath>/share</alfresco.client.contextPath>
    </properties>

16- Once server completes startup process, put the break point in the class file and open share in browser and perform some action where you want to debug. Eclipse will automatically prompt and stop at debug break point.

Note: 
We talked about debugging here, using the same approach we can run alfresco without debug mode. Configure the pom file via "Run > Run Configuration" from main menu (refer step 2 above). And all other steps are same.

For SDK 4.x, see this post:  Alfresco 6.x with SDK4.x and docker command cheatseet


3 comments:

Thanks for your comments/Suggestions.