Skip to main content

spring-loaded rocks !

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 ! 

Comments

Anonymous said…
Jokes Factory : Jokes Factory - Funny Jokes, Whatapp Jokes, Adult Jokes, Romantic Jokes, Friends Jokes, Politician Jokes and much more! http://www.jokesfactory.net/

Popular Posts

Hibernate Generic DAO.

When you use Hibernate and DAO pattern it is a good idea to use a Generic Base Dao. The fallowing code snippet contains GenericDAO that is a base class for all my DAO classes. This GenericDAO uses HibernateDaoSupport from Spring for its implementation if you want you can use JpaDaoSupport or JdbcDaoSupport in your projects. My Generic DAO interface looks like this : package org.joke.myproject.dao.base; import java.io.Serializable; import java.util.List; /** * @author Naiden Gochev * @param <E> * @param <PK> */ public interface GenericDao<E,PK  extends Serializable> {     PK save(E newInstance);     void update(E transientObject);     void saveOrUpdate(E transientObject);     void delete(E persistentObject);     E findById(PK id);     List<E> findAll();     List<E> f...

RichFaces server-side paging with DataTable.

Most of the component toolkits have build in support for server-side paging this days but in rest of the cases you need to customize a little the data model or data provider or component itself to have data paging. The reason why I write this post is because when I first saw richfaces everythink was perfect except the server-side paging. They have paging but it was client side based on JavaScript witch just doesn't work in many cases and I loose a lot of time to understand all models, which model I must extend and how to do it to create a data model with server side paging. At the current version of RichFaces on the demo page information about how to do server-side paging at least exist http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=dataModel&cid=3608154 but like always the JBoss/RedHat/Exadel doesn’t provide us a fast full easy working example and we must loose a lot of time to search for classes in the demo. The reason why I write this post is to giv...

Generate JavaDoc with UML diagrams

In my life many times has happened when I am assigned to a totally new project that I have no idea what it is about, that has to go live in 2 weeks and that I have to fix some issues in this ultra strange code sometimes even code written in different language. On my question is there any documentation the answer is: Yes but it is very old or no. So in short they want me to start working on a project with no documentation at all. My second question is is there a javadoc and the anwer is : yeah … kind of … so I am in a project with 30% javadoc with methods in French language for example ( I don’t know even a single word in French) so in short I am loosing 2 weeks to understand what is using what what is the model what is PersonnePhysique  and what is this crazy domain model. I believe this has happened with everyone of you at least once so what can you do ? You can start digging into the java code like crazy ( like everyone of us have tried many times) You can install ...