Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Javeleon for Rapid Standard Java SE Application Development

DZone's Guide to

Javeleon for Rapid Standard Java SE Application Development

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

This article covers the most fundamental concepts of the Javeleon class reloading system. Javeleon is a development tool that enables arbitrary live class updates within running applications. Javeleon is a Java agent that instruments the bytecode of loaded classes to enable code reloading. It runs on top of the standard JVM and the setup requires only adding a few arguments to the JVM.

Introduction to Javeleon

Javeleon allows Java SE developers to perform live code updates in a test-instance of an application while it is being developed. Javeleon supports changes to methods, fields, constructors, enums, the set of implemented interfaces as well as the super class (see full feature matrix here). Moreover it will preserve the state of existing instances.

Setting up Javeleon

In this section we will create a minimal Java SE application and perform the steps required to run with Javeleon. We will use NetBeans as the IDE in use but any other IDE can be used.

First create a Java SE application. Then copy the following code into the main class:

package org.javeleon.test;

public class JaveleonTest {
        
    private static JaveleonTest test = new JaveleonTest();
        
    public static void main(String[] args) throws InterruptedException {
        while(true){
            Thread.sleep(1000);
    test.doSomething();
        }
    }

    private void doSomething() {
        System.out.println("hello world");
    }

}  

Before running this application we want to enable Javeleon to the project. This is basically done by specifying a few JVM arguments to tell the JVM that a java agent is present. In case you use NetBeans simple install the Javeleon plug-in by adding a NetBeans update center with the URL: http://javeleon.org/javeleon-for-netbeans-7.1/ (replace 7.1 with 7.0 in case you haven’t upgraded your IDE yet and still use 7.0 or 7.0.1). Once installed, there will be a new right-click menu entry saying Javeleon for Java SE projects. Expand the entry and press Add Javeleon to project. This will add the JVM arguments required to run with Javeleon inside a private.properties file.

Here'’s an example of what is generated by the Javeleon plug-in:

javeleon.jar=${netbeans.user}/modules/ext/javeleon.jar
javeleon.bootclasspath=-Xbootclasspath/p:"C:/Users/allang/AppData/Local/Temp/JaveleonBoot/java"
javeleon.agent.args=nbjdk=java;profile=java
javeleon.args=-javaagent:"${javeleon.jar}"="${javeleon.agent.args}" ${javeleon.bootclasspath}
run.jvmargs=${javeleon.args}
In other IDEs, you need to manually add the JVM arguments. For Eclipse, You can find the setup instructions here. It is important that you specify the official temp folder for your OS and insert it into the –Xbootclasspath option. Likewise it is important that whatever you write after JaveleonBoot must match what you declare in the agent arg nbjdk. One example of manually specified JVM arguments is:
-javaagent:C:/Users/you/javeleon.jar=nbjdk=JDK6u29;profile=java -Xbootclasspath/p:"C:/Users/you/AppData/Local/Temp/JaveleonBoot/JDK6u29"
These options are all you need to enable Javeleon.

Setting up Javeleon

Now run the project. Start making changes to the code and save the file once in a while and see how Javeleon picks up your changes inside the running application. For example try making the following changes to the code:

package org.javeleon.test;

public class JaveleonTest {
        
    private static JaveleonTest test = new JaveleonTest();

    private int countdown = 1000;
        
    public static void main(String[] args) throws InterruptedException {
        while(true){
            Thread.sleep(1000);
    test.doSomething();
        }
    }

    private void doSomething() {
        System.out.println("Counting down: " + countdown--);
    }
}
Notice how Javeleon is able to initialize the field automatically when you make the change.

You can make whatever change you like to this class and you’ll see the new behavior kick in. For example, the following code, where we have changed the set of implemented interfaces and added a method, show you some of the great capabilities of Javeleon:

package org.javeleon.test;

public class JaveleonTest implements Runnable {
        
    private static JaveleonTest test = new JaveleonTest();

    private int countdown = 1000;
        
    public static void main(String[] args) throws InterruptedException {
        while(true){
            Thread.sleep(1000);
    test.doSomething();
        }
    }

    private void doSomething() {
        new Thread(this).start();
    }
} public void run() {
        System.out.println("I'm running in the newly added Runnable!");
    }
}

Have fun with Javeleon and please report any issues to support@javeleon.org.

Also, comments and feature requests are also most welcome. We have more features to show in upcoming tutorials, so stay tuned.

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}