Spring Loaded realizes hot update

original
2015/09/16 17:14
Reading amount 1.8W

1. Introduction      

Spring Loaded is an agent implemented based on javaAgent, For more javaAgents, refer to:
Java proxy javassist: http://my.oschina.net/OutOfMemory/blog/309283

Official website: https://github.com/spring-projects/spring-loaded
Current latest version: 1.2.4 RELEASE

2. Description

Current latest version 1.2.4. RELEASE implements the mechanism of monitoring the update of jar packages and hot update of jar packages. At present, the official version can run well on Linux, but there are still bugs in Windows. Someone on the official website has proposed: https://github.com/spring-projects/spring-loaded/issues/145 If you want to test on Windows, you can manually change the source code.

3. Parameters

-Dspringloaded=watchJars=main.jar:other.jar
That is, the watchJars option. Before listening to multiple jars, separate them with:

4. Examples

Take win as an example, You need to manually change the source code and compile it
Test directory:

lib: springloaded-1.2.4.RELEASE.jar
main-0.0.1-SNAPSHOT.jar yes The tested jar packages are generally game logic jar packages

 package org.main; import java.util.concurrent.TimeUnit; /** * Hello world! *  */ public class App { public static void main(String[] args) throws InterruptedException { Reload reload = new Reload(); while (true) { reload.load(); TimeUnit.SECONDS.sleep(2); } } }
 package org.main; public class Reload { public void load() { System.out.println("load....."); } }
run.bat:


 java -javaagent:lib/springloaded-1.2.4.RELEASE.jar -noverify -Dspringloaded=verbose;explain;watchJars=main-0.0.1-SNAPSHOT.jar -jar main-0.0.1-SNAPSHOT.jar pause
Run run.bat
 D:\springloaded\win>java -javaagent:lib/springloaded-1.2.4.RELEASE.jar -noverify -Dspringloaded=verbose; explain;watchJars=main-0.0.1-SNAPSHOT.jar -jar main-0.0. 1-SNAPSHOT.jar SL: [verbose mode on] Full configuration is:verbose; explain;watchJars=main-0.0.1 -SNAPSHOT.jar SL: [explain mode on] Reporting on the decision making process within SpringLoad ed 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=org/main/App classloader=Launcher $Ap pClassLoader typeRegistry=TypeRegistry(id=1325628529, loader=sun.misc.Launcher$Ap pClassLoader) ====remainingPrefix=====jar:file:/D:/springloaded/win/main-0.0.1-SNAPSHOT.jar=== =jarname=====main-0.0.1-SNAPSHOT.jar 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor prePro cess Information: [explanation] Based on the name, type org/main/App is considered to be rel oadable 2015-9-16 16:55:32 org.springsource.loaded. ReloadableType <init> Information: New reloadable type: org.main App (allocatedId=0) TypeRegistry(id=13256285 29, loader=sun.misc.Launcher$AppClassLoader) 2015-9-16 16:55:32 org.springsource.loaded.agent. Watcher addFile Information: Now watching d:  springloaded  win  main-0.0.1-SNAPSHOT.jar 2015-9-16 16:55:32 org.springsource.loaded. TypeRegistry getReloadableType Information:>TypeRegistry. getReloadableType (typeRegistryId=0, typeId=0) 2015-9-16 16:55:32 org.springsource.loaded. TypeRegistry getReloadableType Information:<TypeRegistry. getReloadableType (typeRegistryId=0, typeId=0) returning org.m ain.App 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=org/springsource/loaded/SSMGr classl oader=Launcher$AppClassLoader typeRegistry=TypeRegistry(id=1325628529,loader=sun .misc.Launcher$AppClassLoader) 2015-9-16 16:55:32 org.springsource.loaded. TypeRegistry couldBeReloadable Information: Why NotReloadable? The type org/springsource/loaded/SSMgr is using a packag e name 'org/springsource/loaded/' which is considered infrastructure and types w ithin it are not made reloadable 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=java/lang/InterruptedException class loader=null typeRegistry=null 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=org/main/Reload classloader=Launcher $AppClassLoader typeRegistry=TypeRegistry(id=1325628529, loader=sun.misc.Launcher $AppClassLoader) 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor prePro cess Information: [explanation] Based on the name, type org/main/Reload is considered to be reloadable 2015-9-16 16:55:32 org.springsource.loaded. ReloadableType <init> Information: New reloadable type: org.main Reload (allocatedId=1) TypeRegistry(id=13256 28529, loader=sun.misc.Launcher$AppClassLoader) 2015-9-16 16:55:32 org.springsource.loaded. TypeRegistry getReloadableType Information:>TypeRegistry. getReloadableType (typeRegistryId=0, typeId=1) 2015-9-16 16:55:32 org.springsource.loaded. TypeRegistry getReloadableType Information:<TypeRegistry. getReloadableType (typeRegistryId=0, typeId=1) returning org.m ain.Reload 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=org/springsource/loaded/ISMGr classl oader=Launcher$AppClassLoader typeRegistry=TypeRegistry(id=1325628529,loader=sun .misc.Launcher$AppClassLoader) 2015-9-16 16:55:32 org.springsource.loaded. TypeRegistry couldBeReloadable Information: Why NotReloadable? The type org/springsource/loaded/ISMgr is using a packag e name 'org/springsource/loaded/' which is considered infrastructure and types w ithin it are not made reloadable load..... 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded processing: classname=java/util/concurrent/TimeUnit classl oader=null typeRegistry=null 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded processing: classname=java/util/concurrent/TimeUnit $1 classes sloader=null typeRegistry=null 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=java/util/concurrent/TimeUnit $2 classes sloader=null typeRegistry=null 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=java/util/concurrent/TimeUnit $3 classes sloader=null typeRegistry=null 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=java/util/concurrent/TimeUnit $4 classes sloader=null typeRegistry=null 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=java/util/concurrent/TimeUnit $5 classes sloader=null typeRegistry=null 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=java/util/concurrent/TimeUnit $6 classes sloader=null typeRegistry=null 2015-9-16 16:55:32 org.springsource.loaded.agent. SpringLoadedPreProcessor logPre Process Information: SpringLoaded preprocessing: classname=java/util/concurrent/TimeUnit $7 classes sloader=null typeRegistry=null load..... load..... load.....

Modify the class file in the jar, Load.... In Reload Change to reload   Repackage and overwrite the current jar. Observe the log:

 2015-9-16 16:57:32 org.springsource.loaded.agent. Watcher run Information: Observed last modification time change for d:  springloaded  win  main-0.0.1- SNAPSHOT.jar (lastScanTime=1442393851501) 2015-9-16 16:57:32 org.springsource.loaded.agent. Watcher  ... Omitted reload..... reload.....

Hot update completed!

reference resources: http://www.blogjava.net/landon/archive/2015/07/01/425994.html

Expand to read the full text
Loading
Click to join the discussion 🔥 (6) Post and join the discussion 🔥
Reward
six comment
sixteen Collection
zero fabulous
 Back to top
Top