When Salesforce is life!

Month: February 2013

[Github / Maven] Maven repository using GitHub

This simple post is a reminder on how to create a Maven2 repository and use it with Maven in a “pom.xml” file or in Java Play!. The first step is to create a GitHub Repository (it will be named “maven2”).Then reproduce the folder structure of a Maven Repository, as I did in my “Maven2” repo (https://github.com/enreeco/maven2).For instance, given this artifact (jar):

<groupId>com.rubenlaguna</groupId>
  <artifactId>evernote-api</artifactId>
  <name>Official Evernote API</name>
  <version>1.22</version>

Create these folders:

./com
     ./com/rubenlaguna
     ./com/rubenlaguna/evernote-api
     ./com/rubenlaguna/evernote-api/1.22
     ./com/rubenlaguna/evernote-api/1.22/evernote-api-1.22.jar
     ./com/rubenlaguna/evernote-api/1.22/evernote-api-1.22.pom

Now you have a pubblicly accessible Maven2 repository at https://github.com/[username]/[repoName]/raw/master/ (in my case https://github.com/enreeco/maven2/raw/master/).To consume it in your projects, just add this lines in the “pom.xml” file of your project:

<?xml version="1.0" encoding="UTF-8"?>
<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.echoservice</groupId>
    <version>1.0-SNAPSHOT</version>
    <artifactId>echoservlet</artifactId>
    <repositories>
    <repository>
      <id>myRepository</id>
      <url>https://github.com/enreeco/maven2/raw/master/</url>
    </repository>
    </repositories>
    <dependencies>
 . . .
 </depencencies>
 . . .
</project>

To integrate the maven repo in a Java Play! project (necessary if you’re messing with Heroku), take the “/prject/Build.scala” file and add those lines:

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "evernote-integration"
    val appVersion      = "0.1"

    val appDependencies = Seq(
      "com.rubenlaguna" % "evernote-api" % "1.22", //Evernote Thrift Library
      "com.rubenlaguna" % "libthrift" % "1.0-SNAPSHOT",//Thrift core library
      "postgresql" % "postgresql" % "9.1-901.jdbc4", //Postgres
      "org.apache.httpcomponents" % "fluent-hc" % "4.2.1" //Apache HTTP client
    )

    val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
     resolvers+= "personal maven repo" at "https://github.com/enreeco/maven2/raw/master/"
    )

}

Maven will search for the selected jars in the default locations, but when it’s not finding anything it will search for your personal resolvers.

[Visualforce / Tip] Always add a tag

Always add <apex:pagemessages/> at the beginning of your VF page to see if there are errors in loading/submitting VF page.
If something underneath the Visuarlfoce is wrong, you don’t see anything (no clear log at least)!

I was using the automatic SOQL generation of the “Object__c” standard controller, and to do this I usually use (well, I used to do it in the past, now I only use a series of “{!field}” in a hidden <apex:outputPannel>):

     <apex:inputHidden value="{!Object__c.CreatedDate}" />
     <apex:commandButton value="Do something" action="{!doSomething}"/>

This is clearly a blasphemy,because you cannot set with input hidden a “created date” field, but as I hadn’t wrote this piece of code myself, I didn’t see it immediatly.

Result was that commandLink/ButtonLink was not working, no log provided (exception made for the page load’s initialization debug log), everithing I did made the button simply reloading the page without a real postback.

Using a simple <apex:pagemessages/> I saw the error and manage to know what was the problem.

Powered by WordPress & Theme by Anders Norén