Springload Hot-Deploy Java Application project __java

Source: Internet
Author: User

Thermal deployment is often a problem for operational personnel. Hot deployment In simple terms, is a partial or a file modified, without restarting the program, immediately effective.

The advantage is that a large amount of initialization data may be loaded when the program is initialized, and that restarting the program costs too much; If a program is a single module in a project, restarting can affect other applications.

For Web applications, most are deployed in servlet containers, such as jboss,weblogic,tomcat, which often provide a matching hot-deployment scenario.

But for application procedures, there are often no manufacturers to do this alone.

After my search, found Springload is a better solution. The simple test is as follows.

1, download Springload jar package:

Spring-loaded (https://github.com/spring-projects/spring-loaded)

Maven dependencies: (Not Configured)

<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, put the Springloaded-1.2.3.release.jar below.

3. If it is 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, remember to check for automatic compilation. Project automatically.

Once started, modifying the Java code will take effect immediately.


4, for Yu Yunwi, a lot of tools can not be used, such as eclipse, hot deployment is not so easy.

If you are using MAVEN management, you can configure environment variables:

Maven_opts

-javaagent:repo/springloaded-1.2.3.release.jar-noverify

Or add the maven startup parameter under%mava-home%/bin/mvn.bat:

Set Maven_opts=-javaagent:repo/springloaded-1.2.3.release.jar-noverify

Note that 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 compiling the Xxx.java into the dir directory.

javac-d dir  Xxx.java


As my current directory:


Notice that the package directory of the class is not added after-D.


Post the source code:

Package com.mobile263;

public class Calcutor {public
	
	static int-calc (int a,int b) {return
		a*b;
	}
	

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");
			@Override public
			Void 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);
	}

At the cmd command line, go to the project root directory and execute the MAVEN command:


The result of a modified operation:

Exec Main Class ok! Result=9 @2015-05-20 11:10:57
Exec Main Class ok! Result=9 @2015-05-20 11:10:58
Exec Main Class ok! Result=9 @2015-05-20 11:10:59
Exec Main Class ok! Result=9 @2015-05-20 11:11:00
Exec Main Class ok! Result=9 @2015-05-20 11:11:01
Exec Main Class ok! Result=9 @2015-05-20 11:11:02
Exec Main Class ok! Result=20 @2015-05-20 11:11:03
Exec Main Class ok! Result=20 @2015-05-20 11:11:04
Exec Main Class ok! Result=20 @2015-05-20 11:11:05
Exec Main Class ok! Result=20 @2015-05-20 11:11:06
Exec Main Class ok! Result=20 @2015-05-20 11:11:07
Exec Main Class ok! Result=20 @2015-05-20 11:11:08
Exec Main Class ok! Result=20 @2015-05-20 11:11:09
Exec Main Class ok! Result=20 @2015-05-20 11:11:10
Exec Main Class ok! Result=20 @2015-05-20 11:11:11



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.