实时热更新库 hermes-jvm

码农软件 · 软件分类 · 其他开发相关 · 2019-10-17 11:12:58

软件介绍

程序员分很多种,有测试驱动型,有IDE驱动型,有BOSS驱动型,有错误驱动型。而我就是错误驱动型大军中的一员。我开始把错误当做开发中的一种常态,是我们完成良好软件的必经之路。

作为JAVA大军中的一员,我的编程时间通常是maven-clean-package,等待,测试用例未通过,修改,继续maven...,当然你可能使用不同的工具。但是流程应该也是大同小异。渐渐地,我觉得这个流程是在浪费我的生命。因为很多时候,我只是修正一个小的错误,我不得不运行全套的test,我知道这些testcase中绝大部分都会通过的,但是我还是不得不运行。能写出测试用例的场景还好,更烦的是,需要重新启动程序的场景,maven-clean-package,restart,就这样5分钟就过去,也许我只是想看看几行代码的修改。这种情况每天都在发生,我觉得是时候改变一下我的编程方式了,于是我写实时热更新的库。

这个库我叫做Hermes,取自希腊神话中的赫尔墨斯。使用这个库,一共只有一个简单的API:create示例代码如下:

package com.lvonce;

import static com.lvonce.hermes.EntityFactory.*;

public class App {
    public static void main(String[] args) throws Exception {
		IFoo foo1 = create(IFoo.class, "com.lvonce.JavaFoo");
		IFoo foo2 = create(IFoo.class, "com.lvonce.KotlinFoo");
		IFoo foo3 = create(IFoo.class, "com.lvonce.GroovyFoo");
		Runnable func = new Runnable() {
			public void run() {
				while (true) {
					System.out.println(foo1.hello("msg"));
					System.out.println(foo2.hello("msg"));
					System.out.println(foo3.hello("msg"));
					try {
						Thread.sleep(1000);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}	
		};
		new Thread(func).start();
    }
}

其中,IFoo是一个接口,JavaFoo是java的实现,KotlinFoo是kotlin的实现,GroovyFoo是groovy的实现。使用create创建对象后,你就可以自由的修改相应的.java .kt .groovy文件代码。你将看到程序中的hello被实时热更新了。这就这个库为你节省时间的地方,你可以像写脚本一样享受实时更新,实时看到变化结果的编程体验。没错你在写静态编译的jvm程序。希望这个有点小黑魔法的库能给大家带来方便。

源码地址:https://github.com/thegenius/hermes

项目里有完整的使用示例,在example目录下,可以直接maven clean package运行。

欢迎各种反馈,我喜欢听见你们使用后的声音,因为这会让我觉得开源是有意义的!

本文地址:https://codercto.com/soft/d/16945.html

Data Structures and Algorithms in Java

Data Structures and Algorithms in Java

Robert Lafore / Sams / 2002-11-06 / USD 64.99

Data Structures and Algorithms in Java, Second Edition is designed to be easy to read and understand although the topic itself is complicated. Algorithms are the procedures that software programs use......一起来看看 《Data Structures and Algorithms in Java》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具