0

My Presentation about "Beyond new things in Java" which I held at javaday.bg event.

Posted by JOKe on 7/18/2014 08:24:00 PM in
My Presentation about "Beyond new things in Java" which I held at javaday.bg event, organized by trader.bg. There was recording of everything but you have to contact trader.bg for link since it is not provided on the javaday.bg website.


 

|
0

Patching a Maven library with your custom class.

Posted by JOKe on 7/18/2014 11:01:00 AM in
Sometimes you use a library that has a bug. Or maybe it doesn’t has a bug but you want to change something. Of course if it is an open source you can get the sources… build them … with your change and so on. However this first takes a lot of time and second you need the sources.
What you usually want .. is to just replace one class.. or few classes with something custom… maybe add a line .. or remove a line and so on.
Yesterday… I had an issue with jboss-logging. The version I was using was 3.2.0Beta1 and it turns out that using this version and log4j2 2.0 final basically meant that no log is send to log4j2. The reason was a null pointer exception that was catched in jboss logging class called Log4j2Logger. The bug I submitted is here https://issues.jboss.org/browse/JBLOGGING-107 and it was fixed at the same day. However I will use it as an example since I didn’t knew when this will be fixed.. and I didn’t want to wait till it is fixed.
So I was thinking what I want.. to take the jboss-logging  jar  and replace the file called Log4j2Logger. Basically as you can see in the bug I wanted to replace line 54 to be :
instead of :
this.logger.log(null, loggerClassName, translatedLevel,
parameters == null || parameters.length == 0 ? this.messageFactory.newMessage(message) :
this.messageFactory.newMessage(String.valueOf(message), parameters),
thrown);
to become :
this.logger.log(translatedLevel, parameters == null || parameters.length == 0 ? this.messageFactory.newMessage(message) : this.messageFactory.newMessage(String.valueOf(message), parameters),

And that’s it. Of course I didn’t wanted to do this manually with zip Усмивка but to use maven as well.

So what I did:

1) I created a new maven project and added as dependency the jboss-logging.
2) I set the new project groupid and artifactid as the ones in the dependancy.
I set the version to be something like “3.2.0.Beta1-log4j2-npe-fix” so I added –log4j2-npe-fix
3) I used a plugin that takes the original version, unpacks the original jar in target WITHOUT the class I want to patch in this case Log4j2Logger.class and added my own implementation in the sources of my project.
4) And well thats all... ones I build.. my patched class will go in target.. and the original classes except the class I want to patch will also go in target and voala.. I will have a library which is patched.
The full pom.xml looks like this:

<?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/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>

    <groupId>org.jboss.logging</groupId>
    <artifactId>jboss-logging</artifactId>
    <version>3.2.0.Beta1-log4j2-npe-fix</version>
    <dependencies>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.2.0.Beta1</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.jboss.logging</groupId>
                                    <artifactId>jboss-logging</artifactId>
                                    <version>3.2.0.Beta1</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/classes</outputDirectory>
                                    <excludes>
                                        **/Log4j2Logger.class
                                    </excludes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
 

and that’s it.. the only thing left is to update my project to use my version 3.2.0.Beta1-log4j2-npe-fix instead of the original 3.2.0.Beta1.



I hope this will help to someone to save time.
  
 

|
1

spring-loaded rocks !

Posted by JOKe on 4/22/2014 09:37:00 PM

Today I found spring loaded (https://github.com/spring-projects/spring-loaded)

in short this is a java agent that enables class reloading of already running VM.

Simply this means zero deployment time (in many cases).

It is like a free and open source alternative of JRebel.

Spring Loaded allows you to add/modify/delete methods/fields/constructors. The annotations on types/methods/fields/constructors can also be modified and it is possible to add/remove/change values in enum types.

There is a preliminary java8 support. There is also another project DCEVM ( which is also great but supports only till JRE 6 update 26). More info here http://ssw.jku.at/dcevm/

But lets stop speaking and show you how it works.

In short you just need to pass the agent when starting the vm and that’s it.

>java -javaagent:D:/Downloads/springloaded-1.2.0.BUILD-20140409.201438-12.jar -noverify org.gochev.MainClass

I am using this Build since I am running Java 8 and this is currently the latest .

The code I in my simple app is the following:

A POJO like this :

package org.gochev;

public class DynamicReloadedClass {
private int age = 30;

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
}




and a MainClass like this:



package org.gochev;

import java.util.Scanner;

public class MainClass {
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
while (true) {
System.out.println("test "
+ new DynamicReloadedClass().getAge());
scanner.next();
}
}
}
}


So I can change the DynamicReloadedClass while the main method in the MainClass is looping. You can see this in action here :



http://www.screencast.com/t/KIFIxv7j



Awesome ... and free ! 


|
0

Google Reader alternatives ?

Posted by JOKe on 6/26/2013 01:52:00 PM

None .. no really there is NO Google reader alternatives simply because Google reader is THE BEST.

However since google reader will be shut down in few days and we don’t have a choice and we have to switch somewhere. So what are the alternatives one day before the google shutdown ?

1) Feedly : http://cloud.feedly.com/#latest

I hate it .. no really it is HELL of a BUGGY .. it doesn’t mark my blog posts as read.. it requires some crappy plugins that will fetch the articles in the background otherwise it is not working, the android app is peace of buggy shit with some promotional popular craps and no real full article view for tablets. It is amazingly bad.. it looks shiny but it is shit, it requires login on all your machines each time when you make changes between the machine (work, home, phone). It is unusable even when it looks good :

feedly

It looks good but it is not an alternative.. no my friends its peace of crap that just wants to steal some google reader users.

2) AOL reader : http://reader.aol.com/ currently in  closed beta.

It is not bad actually it looks good it works good (when it works) however it is not working like 30% of the time still it may become a good alternative ones it is done but it wont be done tomorrow so .. nope it doesn’t work for me.

It looks like that :

 

3) Digg Reader : http://digg.com/reader currently in closed beta.

Good idea however it is hell of a buggy doesn’t looks and works very well and maybe some day it will be okei as AOL reader but this day is not today.

It looks like that:

4) NewsBlur, Pulse, Flipboard, NetVibes, Zite are basicaly RSS readers but not a Google reader alternatives.

You can read about all of them here http://gizmodo.com/10-google-reader-alternatives-that-will-ease-your-rss-p-5990540 however I don’t like them at all they look bad and they are useless for a lot of news. Sometimes I have 1500 news per day that I want to scroll as fast as possible and read only the 50 of them which are really liked so this readers to me and I guess for many of you as well cuz this readers simply doesn’t do the job.

So what can we do ? what is left ? yes what is left is the REAL alternative. The real alternative is called

5) Old Reader : http://theoldreader.com/ works and looks like a boss !

First of all no complains about how it works, it marks everything right on time I don’t have to cilck some crappy button “Mark all my articles as read” like in feebly otherwise 50% of your already checked articles are unread … also Feedly doesn’t show you all unreaded articles it is peace of shit anyway Old Reader is awesome and it is not just created a month ago by 3 random php guys who are trying to type something that can read XML file and show html instead it is old product which already have users, which is already stable and proven and it doesn’t require some weird browser extensions. The social plugins are missing indeed share on facebook or on google+ however there are bookmarklets for this I was always wonder before how you can share something before you actually read it just watching the headlines ? it is just strange… Anyway by default the reader looks like this (after last UI changes that the old reader team made) :

I know what you will say : it looks bad.. Indeed I don’t like how it looks as well.. what I did in order to LOVE this reader is well I installed Stylish extension ( I already had it ). Stylish extension gives you a way to apply any css to any website that you visit.. for example you have something in Facebook you don’t wanna see then add a selector and hide it..  so for the old reader there are tons of css styles reader UI is made very nicely and all the css classes are nicely called everything is very easy for customization here is my try if someone want to use it : https://skydrive.live.com/redir.aspx?cid=3917982854a57d45&page=self&resid=3917982854A57D45!176&parid=3917982854A57D45!102&authkey=!&Bpub=SDX.SkyDrive&Bsrc=Share 

Just add this style in Stylish add the URL starting with http://theoldreader.com/ and voala:

oldreader

 

Well that’s it guys – THE OLD READER the ONLY Google reader alternative on 26.06.2013.


|
0

Семинар: Новости в Java платформата.

Posted by JOKe on 7/21/2011 05:12:00 PM

 

Анонса е леко нахално взаимстван от блога на Наков(http://www.nakov.com/blog/2011/07/21/seminar-java-7-java-ee-6-bgjug-27-july-2011/) поради мързел от моя страна да го напиша. Общо взето промените са replace на Найден Гочев с Аз.

 

Имам прекрасна новина за всички Java фенове. След като Java 7 официално излезе, дойде ред и на Българскота общност от Java разработчици да се присъедини към поредицата “Java 7 Launch” събития. Благодарение на много хора :+) ще си направим семинарче и парти по случай Java 7 и новостите от Java света, които идват заедно с нея.

Програма на семинара

    Kакво ново в Java 7?
    Kакво ново в Java EE 6?
    Kакво ново в JavaFX 2.0?
    Kакво ново в JavaME?

Лекциите са част от официалния “Oracle Java 7 Launch Kit”, който е предоставен от Oracle за Българската Java потребителска група (BGJUG) заедно с тениски и други рекламни материали.

Кога и къде?

Семинарът “Новости от Java платформата” ще се проведе на 27 юли (сряда) от 19:00 часа в учебната зала на Академията на Телерик за софтуерни инженери. Адресът е: София, Младост-1, бул. Александър Малинов 33, партер.

Лектор

Лектор ще бъда аз.

Благодарности

Благодарностите за организирането на семинара са за:

    BGJUG – организатор на събитието
    Oracle Corp. които предоставиха Java 7 Launch Kit, тениски и рекламни материали за BGJUG
    Петър Тахчиев, който поръча тениските и launch kit-a.   
    Академия на Телерик – домакин на събитието
    Светлин Наков, който помогна с намирането на домакин ;)



|
0

JavaScript inheritance (object-oriented programming)

Posted by JOKe on 7/05/2011 04:47:00 PM in

 

There are many posts explaining what JavaScript inheritance is how it works, is it bad or good, how it is comparable with Java inheritance with millions of examples using third party apis or function to make inheritance look more like C#/C++/Java Inheritance.

This post is just to show HOW inheritance looks without anything else except browser so next time when you need to find it you can open this post which explains everything you need.

JavaScript uses so called prototype inheritance you don’t need to know more except it is different then a C#/C++/Java way of doing inheritance

Define a class

In JavaScript you can define class like this:

function A(){
    this.aMethod = function (){
        alert("A method");
    }
    this.bMethod = function () {
        alert( "B Method");
    }
}

Yes, yes there are different ways I find this one the most easy one  you can read more about the ways how to create a class in JavaScript here : http://www.phpied.com/3-ways-to-define-a-javascript-class/

Next you have a class how can you use it ?

var a = new A();
a.bMethod(); //will print B method
a.aMethod(); //will print A method

BAM nothing else, easy right?

ok so what if you want to extend this class ?

Prototype Inheritance

First you will create another class:

function B(){
    this.cMethod = function () {
        alert("C method");
    }
}

ok but how can I say that B extends A ? Simple : B.prototype = new A();

Example :

B.prototype = new A();

var b = new B();
b.aMethod(); //will print A method
b.bMethod(); //will print B method
b.cMethod(); //will print C method

Overriding is fine too.

function B(){
    this.bMethod = function() {
        alert("overriding");
    }
    this.cMethod = function () {
        alert("C method");
    }
}

And use it as before ( keep in mind the .prototype = new A is required only ones)

B.prototype = new A();

var b = new B();
b.aMethod(); //will print A method
b.bMethod(); //will print overriding
b.cMethod();// will print C method

Full example:


function A(){
    this.aMethod = function (){
        alert("A method");
    }
    this.bMethod = function () {
        alert( "B Method");
    }
}

function B(){
    this.bMethod = function() {
        alert("overriding");
    }
    this.cMethod = function () {
        alert("C method");
    }
}

B.prototype = new A();

var b = new B();
b.aMethod(); //will print A method
b.bMethod(); //will print overriding
b.cMethod(); //will print C Method

 

Inheritance through Functions

If you don’t like prototypes for some reason you can use a inheritance through functions.

Example:

you just need when you define a class B (the subType) to call this.someFunctionName = supertype and then invoke this.someFunctionName(). Example this.extends = A; this.extends();

Full Example:


function A(){
    this.aMethod = function (){
        alert("A method");
    }
    this.bMethod = function () {
        alert( "B Method");
    }
}

function B(){
    this.extends = A;
    this.extends();
   
    this.bMethod = function() {
        alert("overriding");
    }
    this.cMethod = function () {
        alert("C method");
    }
}

var b = new B();
b.aMethod(); //will print A method
b.bMethod(); //will print overriding
b.cMethod(); //will print C method



UPDATE: Under Internet Explorer if you want to use inheritance through Functions the FUNCTION name that you have to use SHOULD NOT BE "extends" the above example with extends will not work because IE don't like extends :), use some other name like "inheritFrom" for example


|
1

[LINUX] How to find a specific String in file content with specific file name in specific folder

Posted by JOKe on 5/19/2011 12:19:00 PM

 

This is really the dumbest thing ever in linux, there are many many dumb things but this is the dumbest. Ultra trivial task you want to “find a specific string in a file content of specific file type starting from root folder” this is the easiest thing ever, it was not available in Windows XP/98 and because of that I was keeping one JBuilder which can search normally in any java file containing XXX in starting from this folder. But in Windows Vista / 7 this is done EASY just press F3! In Linux on the other hand it is a NIGHTMARE I was having a trivial task which takes… 10 seconds to search for a properties file which contains a default.session.timeout=600 which is a row in this file and this took me more then 30 mins because there are TONS of posts how this is done but none have worked there ware examples using grep, egrep whatever NOTHING is working total CRAP really. So in short I found it somewhere and I want to post it in order to have another POST in google which gives the answers.

So In short:

How to search for a file content in linux in specific file names starting from specific root folder.

find . -name "*.properties" -print | xargs grep default.session.timeout=600

Which will give you all properties files which contains default.session.timeout=600 it doesn’t have to be the match the whole row you can search for just default.session which will give you all files which contains default.session. This command is typed in the folder that you want to start the search from for example /opt/hybris/


|

Copyright © 2009 JOKe's Blog All rights reserved. Theme based on the Theme by Laptop Geek with changes by JOKe. | Bloggerized by FalconHive.