Thursday, February 7, 2013

sbt.ResolveException: download failed: org.slf4j#slf4j-api;1.6.6

Problem


 When I ran play run , I have the following error :

[error] (*:update) sbt.ResolveException: download failed: org.slf4j#slf4j-api;1.6.6!slf4j-api.jar
[warn] some of the dependencies were not recompiled properly, so classloader is not avaialable


Solution

vi ./project/plugins.sbt

You only have to edit this file and add the last version of play (2.1.0) :

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.0")

Then you can launch play run again

Saturday, January 26, 2013

KnowledgeBlackBelt will definitely shut down.

Bad news ! KnowledgeBlackBelt will definitely shut down on Jan 31st 2013.
Content is available for free ...

play 2.1 : Create yout first projetc with IntelliJ Tips


Create a project with Play is easy :

$ play new my-app 
$ cd my-app 
$ play idea


However, I had some diificulties with how to import in IntelliJ.In the documentation, it says that you have to import a module.But it doesn't work for me.
To succes, I've just done the following :

File --> Open

And now it works every times :-)



Sunday, January 6, 2013

java 8 : Functional Interfaces


In this article, we will try to learn new Java 8 concept : functional interface. It's an entry point for using lambdas and other JAVA 8 features ...

Definition from JSR 335

A functional interface is an interface that has just one abstract method, and thus represents a single function contract. (In some cases, this "single" method may take the form of multiple abstract methods with override-equivalent signatures (8.4.2) inherited from superinterfaces; in this case, the inherited methods logically represent a single method.)
In addition to the usual process of creating an interface instance by declaring and instantiating a class, instances of functional interfaces can be created with lambda expressions, method references, or constructor references.
The function descriptor of a functional interface I is a method type—type parameters, formal parameter types, return types, and thrown types—that can be used to legally override the abstract method(s) of I.

 In short, a functional interface is only one interface with just one abstract method. The goal of Functional Interface is to use JAVA 8 feature like lambdas.

Simple example


Here is a short example :

ICode.java

 package fr.dr.practice;

/**
 * Interface with just one abstract method.
 */
public interface ICode {
    String generate(int codeNumber);
}
Main.java

package fr.dr.practice;

/**
 * Created with IntelliJ IDEA.
 */
public class Main {

    public static String generateTmpCode(int newCode) {
        ICode code = new ICode() {
            @Override
            public String generate(int codeNumber) {
                return "MAIN_" + codeNumber + Math.random();
            }
        };
        return code.generate(newCode);
    }

    public static String generateTmpCodeWithLambda(int newCode) {
        ICode icode = codeNumber -> "MAIN_" + codeNumber + Math.random();
        return icode.generate(newCode);
    }

    public static void main(String[] args) {
        System.out.println(Main.generateTmpCode(12));
        System.out.println(Main.generateTmpCodeWithLambda(12));

    }
}

More complex examples

The JSR says the following :

In some cases, this "single" method may take the form of multiple abstract methods with override-equivalent signatures (8.4.2) inherited from superinterfaces; in this case, the inherited methods logically represent a single method.

So, you can make the following because equals method is public in Object class :

public interface ICode {

    String generate(int codeNumber);
    boolean equals(Object obj);
}

But you can't make this because clone method (protected Object clone() throws CloneNotSupportedException {) isn't public in Object class :

public interface ICode {

    String generate(int codeNumber);
    Object clone();
   
}

Function descriptor 

The JSR 335 add also a the concept of Functional descriptor.
Here is an example from JSR :

interface X { void m() throws IOException; }
interface Y { void m() throws EOFException; }
interface Z { void m() throws ClassNotFoundException; }
interface XY extends X, Y {}
interface XYZ extends X, Y, Z {}

// XY has descriptor ()->void throws EOFException
// XYZ has descriptor ()->void (throws nothing)

Conclusion

Functional interface permits to use lambda or other JAVA 8 features.It exists yet some functional interface (e.g : java.util.Comparator ). Java 8 has also a new package : java.util.functions which defines new Functional Interface.You could see this good blog for example with it : http://datumedge.blogspot.fr/2012/06/java-8-lambdas.html.
This article permits me to learn JAVA 8 feature.If you have comments or if you see errors, please post it ! In next article, we will study lambda feature ...



Wednesday, December 26, 2012

Technorati

Hi,

I just add my blog on Technorati with the reference : SNHEY74ZG7EV

Wednesday, December 12, 2012

Paper about CRaSH : a shell to extends the JVM

I've made an article about an interesting new project : CRaSH
It was published on www.developpez.com.Now it is in french but it will be translate.He is a direct link to this paper : http://damienrieu.developpez.com/article/crash_ehcache_spring/ 

CRaSH permits to access to the JVM by Shell and then execute scripts that you have mage in JAVA or Groovy ...

Saturday, November 10, 2012

IntelliJ : shortcut with kde

Recently, I use IntelliJ with KDE.
I notice that some keymap didn't work.For example, The shortcut ALT + 1 which open the projet window.
I replace it by ALT + NUMPAD 1.

I will try to fill an excel google drive document with shortcuts : here