For OPS, thermal deployment is often a problem to think about. The hot deployment simply means that the local or a file is modified without restarting the program and takes effect immediately.
The advantage is that a large amount of initialization data may be loaded when the program is initialized, the cost of restarting the program is too high, and if the program is a single module in the project, a restart can affect other applications.
For Web applications, most are deployed in servlet containers, such as jboss,weblogic,tomcat, which often provide a matching thermal deployment scenario.
But for the application program, often there is no factory alone to do this thing.
After my search, found that springload is a better solution. The simple test is as follows.
1. Download the Springload jar package:
Spring-loaded (https://github.com/spring-projects/spring-loaded)
Maven dependency: (not configurable)
<dependency><groupid>org.springframework</groupid><artifactid>springloaded</ Artifactid><version>1.2.3.release</version></dependency>
2. Create the repo directory under the project root directory and put the Springloaded-1.2.3.release.jar below.
3. If eclipse, add the JVM startup parameters to the run configuration of the main class:
-javaagent:repo/springloaded-1.2.3.release.jar-noverify
Note the path.
If it's in Eclipse, check automatic compilation. Project automatically.
Once started, modifying the Java code will take effect immediately.
4, for operations, a lot of tools can not be used, such as eclipse, hot deployment is not so easy.
If you use Maven management, you can configure environment variables:
Maven_opts
-javaagent:repo/springloaded-1.2.3.release.jar-noverify
Or add Maven startup parameters under%mava-home%/bin/mvn.bat:
Set Maven_opts=-javaagent:repo/springloaded-1.2.3.release.jar-noverify
Note The path is the root directory of the project.
Give springload to start the project.
If you modify a Java class, how does it take effect immediately?
Compiles the file to the specified directory. such as the Xxx.java compiled to the dir directory.
javac-d dir Xxx.java
As in my current directory:
Note-D does not add the class's package directory after.
Paste out the source code:
Package Com.mobile263;import Java.text.simpledateformat;import Java.util.date;import java.util.timer;import Java.util.timertask;public class Console {public static void Main (string[] args) { timer timer = new Timer ();
timertask task = new TimerTask () {SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"); @Overridepublic Voi D run () {int res = CALCUTOR.CALC (4, 5); System.out.println ("Exec Main Class ok! result= "+res +" @ "+sdf.format (new Date ()));}; Timer.schedule (Task, 1000, 1000);}}
On the cmd command line, go to the project root and execute the MAVEN command:
Results of a modified run:
Exec Main Class ok! Result=9 @2015-05-20 11:10:57exec Main Class ok! Result=9 @2015-05-20 11:10:58exec Main Class ok! Result=9 @2015-05-20 11:10:59exec Main Class ok! Result=9 @2015-05-20 11:11:00exec Main Class ok! Result=9 @2015-05-20 11:11:01exec Main Class ok! Result=9 @2015-05-20 11:11:02exec Main Class ok! Result=20 @2015-05-20 11:11:03exec Main Class ok! Result=20 @2015-05-20 11:11:04exec Main Class ok! Result=20 @2015-05-20 11:11:05exec Main Class ok! Result=20 @2015-05-20 11:11:06exec Main Class ok! Result=20 @2015-05-20 11:11:07exec Main Class ok! Result=20 @2015-05-20 11:11:08exec Main Class ok! Result=20 @2015-05-20 11:11:09exec Main Class ok! Result=20 @2015-05-20 11:11:10exec Main Class ok! Result=20 @2015-05-20 11:11:11
Springload Hot Deploy Java Application project