Spring load hot deployment Java Application project, java hot deployment

Source: Internet
Author: User

Spring load hot deployment Java Application project, java hot deployment

For O & M personnel, hot deployment is a problem that often needs to be considered. In short, hot deployment takes effect immediately after modification to a local file or a file does not need to restart the program.

The advantage is that during program initialization, a large amount of initialization data may be loaded, and the restart of the program is too costly. If the program is a single module in the project, restarting will affect other applications.

Most web programs are deployed in Servlet containers, such as jBoss, weblogic, and tomcat. These containers often provide supporting hot deployment solutions.

However, for the application program, there are often no manufacturers to do it alone.

I found that springload is a good solution. The following is a simple test.

1. Download The SpringLoad jar package:

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

Maven dependency: (not configured)

<dependency><groupId>org.springframework</groupId><artifactId>springloaded</artifactId><version>1.2.3.RELEASE</version></dependency>

2. Create a repo directory under the project root directory and put the springloaded-1.2.3.RELEASE.jar below.

3. If eclipse is used, add the JVM startup parameter in the run configuration of the main class:

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

Note the path.

In eclipse, check the automatic compilation check box. Project Automatically.

After the startup, the modified java code will take effect immediately.


4. For O & M, many tools cannot be used. For example, for eclipse, hot deployment is not that easy.

If maven is used for 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.

Submit it to springload to start the project.

If a java class is modified, how does one take effect immediately?

Compile the file to the specified directory. For example, compile xxx. java to the dir directory.

javac -d dir  xxx.java


For example, my current directory:

javac -d target\mvnproject-1.0-SNAPSHOT\WEB-INF\classes src\main\java\com\mobile263\Calcutor.java 

Note: Do not add the package directory of the class after-d.


Paste 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");@Overridepublic 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);}}

Run the CMD command to enter the project root directory and run the maven command:

mvn exec:java -Dexec.mainClass="com.mobile263.Console" 

Result After modification:

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



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.